fix: emit close after normal WebSocket shutdown - #11
Merged
Merged
Conversation
poly-william
approved these changes
Sep 23, 2026
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.
Changes
Emit
closewhen a remote WebSocket shuts down normally. Previously, close codes 1000 and 1001 ended the receive loop without notifying subscribers.Add real connection regressions for both markets and private streams, including abnormal closes, local close, cancellation and listener errors. Bump the package version to 1.0.2 for the existing publishing workflow.
Testing
websockets==13.0.Checklist
pytest)ruff check .)mypy polymarket_us)Note
Low Risk
Small, targeted change to event emission on disconnect plus regression tests; no auth or API contract changes.
Overview
Fixes WebSocket lifecycle signaling so subscribers get a
closeevent when the server ends the stream without raisingConnectionClosed(e.g. normal close codes 1000/1001).BaseWebSocket._message_loopnow emitsclosein thetry/exceptelsebranch after the receive loop exits cleanly, while existing behavior forConnectionClosed, listener failures (error), and client-initiated shutdown (cancelled task, no extraclose) stays the same.Adds
TestWebSocketLifecycleintegration tests for markets and private streams (remote close codes, localclose, task cancellation, heartbeat listener errors). Package version is bumped to 1.0.2.Reviewed by Cursor Bugbot for commit 87385ad. Bugbot is set up for automated code reviews on this repo. Configure here.