fix(server): preserve directory events across reloads - #42632
Conversation
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
|
The following comment was made by an LLM, it may be inaccurate: One potentially related PR found: #39349: fix(app): recover from a silently dead event stream This PR may be related because it also addresses event stream issues in the context of the app consuming server events. Your current PR (42632) fixes the server side by keeping directory event streams alive across reloads, while #39349 appears to handle client-side recovery when event streams become unresponsive. They complement each other in improving event stream reliability. |
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
Issue for this PR
Closes #36495
Type of change
What does this PR do?
A directory-scoped
/eventstream currently ends when its instance is disposed, even though the subscription is keyed by the stable directory and the replacement instance emits to the same process-wide bus. This keeps the stream open across disposal/recreation while still forwardingserver.instance.disposedas an informational event.The bus subscriptions now live for the actual response-body lifetime and are removed when the client socket closes, avoiding a listener leak.
How did you verify your code works?
Added regression tests showing that one connection receives the disposal event and later events from the replacement instance, and that a real Node/Bun socket disconnect returns the global listener count to baseline. The focused tests pass (5 tests), as does the OpenCode typecheck.
Screenshots / recordings
N/A — server SSE behavior only.
Checklist