Skip to content

FIX finish WebSocket conversation cleanup before cancellation - #2428

Open
Roman Lutz (romanlutz) wants to merge 2 commits into
microsoft:mainfrom
romanlutz:romanlutz-daily-audit-2026-08-19
Open

FIX finish WebSocket conversation cleanup before cancellation#2428
Roman Lutz (romanlutz) wants to merge 2 commits into
microsoft:mainfrom
romanlutz:romanlutz-daily-audit-2026-08-19

Conversation

@romanlutz

Copy link
Copy Markdown
Contributor

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 propagates CancelledError.

Tests and Documentation

Added a deterministic unit test that cancels cleanup while close() is blocked and verifies:

  • cleanup remains pending until the close completes
  • the connection is closed exactly once
  • cancellation propagates after close completes
  • no stale conversation entry remains

Validation included 31 focused WebSocket tests, 1,856 attack/scenario/WebSocket tests, Ruff, targeted ty, pre-commit hooks, and git diff --check.

Documentation changes were not applicable. JupyText was not run because no notebook or documentation source changed.

Copilot AI added 2 commits August 19, 2026 01:40
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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

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.

3 participants