Skip to content

fix: Stop dispatching messages after close - #362

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

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

Conversation

@brennanbutler01

@brennanbutler01 brennanbutler01 commented Sep 18, 2026

Copy link
Copy Markdown

Problem

When several events arrive in one response chunk, calling close() from the first listener still delivers the remaining events with readyState === CLOSED. Reproduced on 4.1.0 (the 4.x release used by the downstream application), published 5.1.1, and current main.

The event dispatch steps require dispatch to stop when the connection is closed. Check the state at the parser's event callback so a listener can close the connection before another buffered event is delivered. No public API changes.

Verification

  • Two regressions failed before the fix: ordinary and named events each delivered three messages instead of one. Both now pass, with two controls that receive all three messages while open.
  • Tests use a real local HTTP server. The closing cases buffer its response into one chunk so transport fragmentation cannot hide the bug.
  • Full Node suite: 48 passed, one existing browser-only skip.
  • Full Chromium and desktop WebKit suites: 49 passed each.
  • Full Bun 1.3.10 suite: 48 passed, one existing browser-only skip.
  • Full workerd suite: 41 passed, seven existing expected failures, and one existing skip. Its console warnings and network-error log also reproduce on untouched main.
  • TypeScript 7.0.2 source build, full test/configuration typecheck, and browser type-compatibility check pass. Oxlint, changed-file formatting, and git diff --check pass.
  • The built JavaScript export also passes the standalone local-server reproduction.

Verified on macOS with Node 24.13.0, Vitest 4.1.10, and Playwright 1.61.1. Firefox, iOS Safari, Deno, and happy-dom were not run. Local verification reused an isolated toolchain; dependency manifests and lockfiles are unchanged. Includes a patch changeset.

Prepared with OpenAI Codex assistance, including the reproduction, implementation, tests, and local review.

Check connection state before dispatching each parsed event so closing from a listener suppresses the remaining messages in the same chunk. Add real-server regressions for ordinary and named events, open-connection controls, and a patch changeset.
Copilot AI lite review requested due to automatic review settings September 18, 2026 09:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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.

2 participants