Skip to content

Raise TimeoutError instead of queue.Empty in WebSocketSession#139

Merged
frankie567 merged 2 commits intomainfrom
copilot/raise-timeouterror-in-websocketsession
Mar 28, 2026
Merged

Raise TimeoutError instead of queue.Empty in WebSocketSession#139
frankie567 merged 2 commits intomainfrom
copilot/raise-timeouterror-in-websocketsession

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 28, 2026

WebSocketSession.receive() (and derived methods) leaked queue.Empty on timeout — an internal implementation detail. AsyncWebSocketSession already raises TimeoutError via anyio.fail_after(), so sync and async APIs were inconsistent.

Changes

  • WebSocketSession.receive(): Catches queue.Empty from queue.Queue.get() and re-raises as TimeoutError
  • Docstrings: Updated receive(), receive_text(), receive_bytes(), receive_json() to document TimeoutError instead of queue.Empty
  • Tests: Added test_receive_timeout covering the new behaviour

Before / After

# Before
try:
    event = ws.receive(timeout=2.0)
except queue.Empty:  # implementation detail leaking through
    ...

# After
try:
    event = ws.receive(timeout=2.0)
except TimeoutError:  # consistent with AsyncWebSocketSession
    ...

💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.

Copilot AI linked an issue Mar 28, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Raise TimeoutError instead of queue.Empty in WebSocketSession Raise TimeoutError instead of queue.Empty in WebSocketSession Mar 28, 2026
Copilot AI requested a review from frankie567 March 28, 2026 14:29
@frankie567 frankie567 marked this pull request as ready for review March 28, 2026 14:30
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 28, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.51%. Comparing base (96dd777) to head (3241a91).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #139      +/-   ##
==========================================
- Coverage   99.83%   99.51%   -0.33%     
==========================================
  Files           5        5              
  Lines         612      615       +3     
==========================================
+ Hits          611      612       +1     
- Misses          1        3       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@frankie567 frankie567 merged commit 0d73695 into main Mar 28, 2026
16 of 17 checks passed
@frankie567 frankie567 deleted the copilot/raise-timeouterror-in-websocketsession branch March 28, 2026 17:57
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.

Raise TimeoutError instead of queue.Empty

3 participants