Skip to content

Raise WebSocketDisconnect after duplicate close#3352

Open
ishaanlabs-gg wants to merge 1 commit into
Kludex:mainfrom
ishaanlabs-gg:fix-websocket-duplicate-close-disconnect
Open

Raise WebSocketDisconnect after duplicate close#3352
ishaanlabs-gg wants to merge 1 commit into
Kludex:mainfrom
ishaanlabs-gg:fix-websocket-duplicate-close-disconnect

Conversation

@ishaanlabs-gg

@ishaanlabs-gg ishaanlabs-gg commented Jun 30, 2026

Copy link
Copy Markdown

Summary

Fixes #2766.

WebSocket.send() now raises WebSocketDisconnect when the application-side websocket state is already disconnected. This matches the existing disconnect exception used elsewhere in the websocket API and leaves the receive-after-disconnect path unchanged.

Checklist

  • I understand that this PR may be closed in case there was no previous discussion. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.

No documentation update was needed because this keeps the existing websocket exception type consistent rather than adding a new API.

Verification:

  • .venv-codex/bin/python -m pytest tests/test_websockets.py::test_duplicate_close tests/test_websockets.py::test_duplicate_disconnect -q
  • .venv-codex/bin/python -m pytest tests/test_websockets.py -q
  • .venv-codex/bin/python -m ruff format --check --diff starlette tests
  • .venv-codex/bin/python -m ruff check starlette tests
  • git diff --check

Review in cubic

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

Re-trigger cubic

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.

Replace RuntimeError with WebSocketDisconnected once the socket has been disconnected

1 participant