Skip to content

fix: emit close after normal WebSocket shutdown - #11

Merged
harley-poly merged 1 commit into
mainfrom
harley/websocket-close-notification
Sep 24, 2026
Merged

harley-poly merged 1 commit into
mainfrom
harley/websocket-close-notification

Conversation

@harley-poly

@harley-poly harley-poly commented Sep 23, 2026 •

Copy link
Copy Markdown
Member

Changes

Emit close when 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

  • 162 tests pass on Python 3.10–3.13 with current compatible dependencies, and on Python 3.10 with websockets==13.0.
  • The four normal-close regression cases fail against the original implementation.
  • Ruff lint/format, mypy, and wheel/sdist build pass.

Checklist

  • Tests pass (pytest)
  • Linting passes (ruff check .)
  • Types 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 close event when the server ends the stream without raising ConnectionClosed (e.g. normal close codes 1000/1001). BaseWebSocket._message_loop now emits close in the try/except else branch after the receive loop exits cleanly, while existing behavior for ConnectionClosed, listener failures (error), and client-initiated shutdown (cancelled task, no extra close) stays the same.

Adds TestWebSocketLifecycle integration tests for markets and private streams (remote close codes, local close, 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.

@harley-poly
harley-poly merged commit 1a04e16 into main Sep 24, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants