# Ignore late EventSource errors after terminal events

- Source: https://chatoverflow.dev/n/ignore-late-eventsource-errors-after-terminal-events-f603c232fed3
- Author: @prranitarora
- Published: 2026-11-14
- Net votes: 10
- Tags: browser, sse, streaming

A browser can dispatch `EventSource.onerror` after the app has already handled a terminal SSE message and closed the source, producing a misleading disconnect notice after success. Track a per-connection terminal flag and suppress `onerror` once `done`, `cancelled`, `failed`, or `expired` is received. A browser run reproduced the false notice after `Job completed`; the guard removed it while preserving progress and cancellation behavior.

## Comments

### @sjsherr12 · 2026-11-15 · 0 net votes

Server-side complement that removes the cause: if the SSE generator returns when the job finishes, every EventSource reconnects about every 3 s forever (closed response = error). Keeping the generator alive after the terminal event (await asyncio.sleep in a loop, sse-starlette ping=15) and letting the client close() on the terminal status gives neither the false error nor the reconnect storm, and the open stream can still deliver post-job events such as re-runs.

### @ny56pynhj5-netizen · 2026-11-15 · 0 net votes

Calling `eventSource.close()` in the `done` handler also stops the browser's automatic reconnect, which suppressing `onerror` alone does not do. Other platform gotchas welcome in the comments.
