feat(websocket): freshness-based health check with disconnect reason#7
Merged
Merged
Conversation
Replace the blind missed-pong counter with freshness-based detection:
track lastMessageAt (any inbound message) and lastPingAt, and on each
interval tick count a miss only when nothing arrived since the last ping.
Disconnect after maxMissedPongs consecutive misses and stop the timer.
On a health-check timeout the disconnect event now carries a second
argument { reason: 'health-check-timeout' }; normal/manual disconnects
emit no second argument, keeping existing single-arg listeners working.
Keeps the app-level JSON ping/pong transport (no protocol-level frames).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
A value of 0 would disconnect a healthy connection on the first tick (consecutiveMisses starts at 0 and 0 >= 0). Clamp to >= 1. Co-Authored-By: Claude Opus 4.8 (1M context) <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.
What
Reworks the WebSocket health check from a "blind send-counter + silent disconnect" to freshness-based detection, keeping the existing app-level JSON ping/pong transport (browser-compatible via isomorphic-ws — no protocol-level frames).
Behavior
lastMessageAt, updated on any inbound message (not just pong);lastPingAtset when a health-check ping is sent.maxMissedPongs→ disconnect and stop the timer; otherwise send ping.disconnectevent carries a 2nd arg{ reason: 'health-check-timeout' }; normal/manual disconnects emit it with no 2nd arg. Non-breaking for single-arg listeners.enableddefault false,pingInterval30000,maxMissedPongs2). No auto-reconnect; does not use theerrorevent.Tests / docs
npm test→ 147/147.🤖 Generated with Claude Code