Skip to content

Cancel a pending streaming handshake on disconnect - #311

Open
codebanditssss wants to merge 1 commit into
AssemblyAI:masterfrom
codebanditssss:audit/round2-python-connect-lifecycle
Open

codebanditssss wants to merge 1 commit into
AssemblyAI:masterfrom
codebanditssss:audit/round2-python-connect-lifecycle

Conversation

@codebanditssss

Copy link
Copy Markdown

Fixes #309.

connect() now reserves the single-use connection before the handshake's first await and records its task. disconnect() cancels and awaits a pending connect before tearing down. A cancelled connect closes the socket and HTTP client and re-raises CancelledError. The existing handshake and retry code moves unchanged into _connect(). Disconnect skips the cancel when it runs inside the connect task itself, for example from a handshake error callback.

Tests

tests/unit/test_streaming_connect_lifecycle.py uses a real local WebSocket server whose upgrade response is held until disconnect returns. It covers disconnect with and without terminate, concurrent connects, reuse after a cancelled connect, a normal connection, and repeated disconnect.

  • Unchanged source: 4 failed, 1 passed (open_sockets=1 after disconnect). Fixed: 5 passed (open_sockets=0).
  • Full offline unit suite: 1039 passed on Python 3.12/websockets 17 and Python 3.11/websockets 11.
  • Ruff check/format pass. mypy on async_client.py reports the same 15 diagnostics as the unchanged upstream file.

Bumps the version to 1.10.15 so it doesn't collide with #307 and the #308 fix.

This branch has not been deployed

No deployments
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.

AsyncRealTimeTranscriber.disconnect() returns while a pending handshake later opens a live session

1 participant