Repository navigation
fix(server): release SSE streams when a Bun client disconnects - #44341
sahiljagtap08 wants to merge 1 commit into
Conversation
Well-scoped workaround for a nasty class of leak — hooking
Minor: the |
|
Automated PR Cleanup Thank you for contributing to opencode. Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions. This PR was closed because it matched the following cleanup criteria:
PRs created within the last month are not affected by this cleanup. If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate. Thanks again for taking the time to contribute. |
Issue for this PR
Closes #36311
Type of change
What does this PR do?
On the pinned Bun (1.3.14),
node:httpdoes not emitServerResponse"close" when the client disconnects (oven-sh/bun#14697).@effect/platform-nodeinterrupts the request fiber from exactly that event, so when a TUI drops its/api/eventSSE connection the server side event stream never gets released. It keeps writing heartbeats into a dead socket, which is the state captured in the issue: server alive, listener open, health unresponsive, one core pinned in the native write path.The fix is the bridge suggested in the issue: on Bun only, destroy the response from the request "aborted" event, which makes Bun emit the missing "close" so Effect can interrupt the stream and release its event subscription. The helper lives in core and is applied to both places we create a
node:httpserver, the V1 server layer and the V2servecommand.How did you verify your code works?
Added a test that opens an SSE response, aborts the client, and asserts the response "close" event fires. Without the bridge the event never fires on Bun 1.3.14 (verified with a copy of the test against a raw
createServer), with the bridge it fires immediately. A second test confirms normally completed responses are not destroyed.bun test test/util/http-server.test.tsin packages/core: 2 pass. Typecheck passes for core, cli, and opencode.Screenshots / recordings
Not a UI change.
Checklist