Repository navigation
Stop the broadcaster from losing cancellations on Python 3.11 - #7
Merged
Merged
Conversation
asyncio.wait_for on 3.11 returns normally when it is cancelled just as the wrapped send completes. gather then raises a bare CancelledError that anyio does not recognise as its own, so cancelling a hub or browser handler during a broadcast could leak the cancellation. This made test_hub_ws fail in about half of CI runs and blocked deploys. asyncio.timeout handles cancellation correctly and keeps the same per-client send timeout. Co-Authored-By: Claude Opus 5.5 <[email protected]>
hyperloop-cornell
approved these changes
Oct 14, 2026
hyperloop-cornell
left a comment
Owner
There was a problem hiding this comment.
lgtm
simple timeout fix
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.
Summary
Broadcaster._sendnow usesasyncio.timeout()instead ofasyncio.wait_for()for the per-client send timeout.wait_forreturns normally if it is cancelled just as the wrapped send finishes, so the cancellation is lost.gatherthen raises a bareCancelledErrorthat anyio doesn't recognise as its own, and the error escapes the cancel scope.concurrent.futures.CancelledErrorfromWebSocketTestSession.__exit__intests/test_hub_ws.py. Which test fails varies; it is usuallytest_hub_status_broadcast. Since at least Sep 27 it has failed the hyperloop-guitest-apijob in about half of runs.SEND_TIMEOUT_SECONDSstill raisesTimeoutErrorand is dropped.test_slow_browser_is_droppedstill passes.Merge notes
hyperloop-cornell/hyperloop-gui#23 pins this branch's commit (
46e47f2), so merge this PR first and use a merge commit (not squash). Otherwise the pinned commit is not onmain.Test plan
tests/test_hub_ws.py100 times on Python 3.11 (python:3.11-slim, same as CI): 50/100 runs failed before the fix, 0/100 afterwait_for; full suite 80 passed🤖 Generated with Claude Code