feat(websocket): freshness-based health check with disconnect reason#18
Open
kevinypfan wants to merge 2 commits into
Open
feat(websocket): freshness-based health check with disconnect reason#18kevinypfan wants to merge 2 commits into
kevinypfan wants to merge 2 commits into
Conversation
Replace the blind missed-pong counter (which raised inside a Timer thread)
with freshness-based detection: track last_message_at (any inbound message)
and last_ping_at, and on each interval tick count a miss only when nothing
arrived since the last ping. Disconnect after max_missed_pongs consecutive
misses and stop the timer.
On a health-check timeout the disconnect event is now emitted via the pyee
EventEmitter with an extra {"reason": "health-check-timeout"} argument;
normal/manual disconnects emit without it, keeping existing listeners
working. Keeps the app-level JSON ping/pong transport.
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 (consecutive_misses starts at 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
Python counterpart of the Node freshness-based WebSocket health check. Keeps app-level JSON ping/pong.
Behavior
last_message_atupdated on any inbound message; freshness compared against the last ping each tick.max_missed_pongs→ disconnect. Replaces the oldraise Exceptioninside the Timer thread.disconnectevent with a{ reason: 'health-check-timeout' }payload (via pyee); normal disconnect has none. Non-breaking.enableddefault False,ping_interval30000,max_missed_pongs2). No auto-reconnect; noerrorevent.Tests / docs
TestWebSocketHealthCheckintests/test_websocket_client.py→ 29 passed.🤖 Generated with Claude Code