Repository navigation
[Bugfix #580] Fix SSE connection leak — server never cleans up disconnected clients - #581
Merged
waleedkadous merged 2 commits intoFeb 28, 2026
Merged
Conversation
…leanup, and multi-event listeners
…/error and deduplication
Contributor
Author
Architect ReviewLow-risk server-side bugfix. Three-layer approach is solid: event listeners with dedup guard, heartbeat sweep, and dead-client detection during broadcast. Codex's Playwright E2E ask is overkill for this — unit tests cover the logic. Approved — please merge. Architect review |
waleedkadous
deleted the
builder/bugfix-580-bug-sse-connections-leak-serve
branch
February 28, 2026 14:37
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #580
Root Cause
SSE connections leaked because:
req.on('close')was listened to —res.on('close')andres.on('error')were not, so some disconnect signals were missedbroadcastNotificationswallowed write errors — the catch block caught exceptions but never removed the dead client from thesseClientsarrayFix
Three changes, all in the SSE server infrastructure:
1. Heartbeat interval (
tower-server.ts):heartbeat\n\n(SSE comment) to every client2. Dead client cleanup in
broadcastNotification(tower-server.ts)res.destroyedandres.writableEndedbefore writing3. Multi-event cleanup in
handleSSEEvents(tower-routes.ts)req.on('close'),res.on('close'), ANDres.on('error')cleanedflag) ensures cleanup runs exactly once even if multiple events fireTest Plan
removes SSE client on res close— validatesres.on('close')cleanupremoves SSE client on res error— validatesres.on('error')cleanuponly cleans up once even if multiple close events fire— validates deduplication