FIX finish WebSocket conversation cleanup before cancellation - #2428
Open
Roman Lutz (romanlutz) wants to merge 2 commits into
Open
FIX finish WebSocket conversation cleanup before cancellation#2428Roman Lutz (romanlutz) wants to merge 2 commits into
Roman Lutz (romanlutz) wants to merge 2 commits into
Conversation
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 5cd848f4-78c8-4b36-83c6-70f07c323896
| try: | ||
| await asyncio.shield(close_future) | ||
| except asyncio.CancelledError: | ||
| await close_future |
Contributor
There was a problem hiding this comment.
there seems to be a narrow inconsistency with cleanup_target_async in that if the websocket close task (await close_future) fails, this method will raise the close exception while cleanup_target_async preserves a CancelledError
Justin Song (jsong468)
approved these changes
Aug 19, 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.
Description
Per-conversation WebSocket cleanup removed the connection from tracking before awaiting
close(). If the cleanup task was cancelled at that point, the socket could remain open with no tracked handle available for later cleanup.This change aligns
cleanup_conversation_async()with the target's existing whole-target cleanup contract: it shields the close operation, waits for it to finish, and then propagatesCancelledError.Tests and Documentation
Added a deterministic unit test that cancels cleanup while
close()is blocked and verifies:Validation included 31 focused WebSocket tests, 1,856 attack/scenario/WebSocket tests, Ruff, targeted
ty, pre-commit hooks, andgit diff --check.Documentation changes were not applicable. JupyText was not run because no notebook or documentation source changed.