Repository navigation
fix(relay): drop unresponsive browser sockets so they stop holding stream slots - #709
Merged
Merged
Conversation
…ream slots A browser tab that disappears without a close handshake (laptop asleep, phone off wifi) kept its relay socket open until nginx's 24h read timeout, along with up to four session channels each. Enough of these filled the machine's 32-channel budget and every new session stream was refused, so sessions stopped loading on codekin.ai while REST kept working. - BrowserHub pings every browser socket every 30s and terminates those that did not answer the previous ping; the normal close path releases their channels. Browsers answer protocol pings natively. - Log refused stream opens on the relay with the error code, and log relay-initiated channel closes on the connector, so the open/close lines in the connector log balance. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Problem
On codekin.ai, sessions stopped loading while the session list (REST) kept working. The connector stopped receiving
stream_openafter ~19:36 yesterday, while the relay audit log still showedsession_viewedattempts, so the relay was refusing streams before forwarding them.Cause:
BrowserHubhas no liveness check on browser sockets, and nginx keeps/relay/sockets for up to 24h (proxy_read_timeout 86400). A tab that vanishes without a close handshake keeps its socket — and up toMAX_CHANNELS_PER_CLIENT(4) channels — counted againstMAX_CHANNELS_PER_MACHINE(32). After about eight such tabs, every new stream getstooManyChannels. Restarting the connector cleared it, which matches this explanation (a reconnect runsfailPendingand drops all channels).Changes
BrowserHubsends a WebSocket ping to every client every 30s and terminates any socket that missed the previous ping. Termination runs the existing close path, which releases its channels on the machine. Browsers answer protocol pings themselves, so the frontend doesn't change.Tests
autoPong: falsegets dropped and its local session socket closes. This test fails without the fix.server/relay: 415/415 pass;tsc --noEmitis clean.🤖 Generated with Claude Code