Skip to content

fix: stop dispatching SSE events after close - #364

Open
zubairchowdhury888-art wants to merge 1 commit into
EventSource:mainfrom
zubairchowdhury888-art:fix/stop-dispatch-after-close
Open

zubairchowdhury888-art wants to merge 1 commit into
EventSource:mainfrom
zubairchowdhury888-art:fix/stop-dispatch-after-close

Conversation

@zubairchowdhury888-art

Copy link
Copy Markdown

Summary

When multiple SSE events arrive in a single buffered chunk, calling
EventSource.close() from the first event listener previously allowed
subsequent buffered events to continue dispatching.

This change adds a closed-state guard to stop event dispatch once the
EventSource has reached CLOSED.

Fixes #362

Regression test

Added a regression test where:

  • first, second, and third events arrive in a single chunk
  • the EventSource is closed from the first event listener
  • only the first event is expected to be dispatched

The unmodified upstream implementation reproduced the issue:

messages dispatched: expected 3 to be 1

The same test passes after the fix.

Verification

  • Node: 45 passed, 1 skipped
  • Targeted regression: 1 passed, 45 skipped
  • Lint/typecheck: 0 warnings, 0 errors
  • happy-dom: 42 passed, 4 expected-fail
  • workerd: 1 failure, 37 passed, 7 expected-fail; the failure was verified as pre-existing against upstream
  • Browser suite could not run because the Playwright/Vitest browser configuration crashes during CLI startup in this environment
  • Bun/Deno/iOS were not run because those runtimes are not installed

Changes

  • src/EventSource.ts — closed-state guard
  • test/client.test.ts — regression test
  • .changeset/stop-dispatch-after-close.md — patch changeset

No public API change and no unrelated refactoring.

The implementation is intentionally minimal: it prevents further event dispatch when the EventSource is already CLOSED.

Once the EventSource has been closed - including by a listener during a
previous event's dispatch, when several parsed events arrive in one
chunk - the event dispatch steps stop and no further buffered events
are dispatched, per the EventSource specification.

Fixes EventSource#362

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant