Skip to content

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

Open

Description

@codebanditssss

AsyncRealTimeTranscriber.disconnect() does not own a connect() that is still in its WebSocket handshake. Disconnect sets the stop event, finds no socket or tasks, and returns. The handshake then completes, installs a live socket and starts the read/write loops, after cleanup has already returned. Nothing closes that session unless the caller calls disconnect() again.

Reproduction

At 0ba094c, with a local WebSocket server that holds its upgrade response, valid 16 kHz parameters and default timeouts:

  1. task = asyncio.create_task(client.connect(params))
  2. Wait until the server receives the upgrade request.
  3. await client.disconnect() (also with terminate=True).
  4. Release the upgrade response; await task.

Expected

Disconnect cancels the pending connect, and no session is open after it returns.

Actual

stopped_on_return=False result=NoneType open_sockets=1

connect() returns normally and the server holds an open session that the SDK never closes. The same gap lets two concurrent connect() calls both pass the single-use guard, since the guard is checked before the handshake's first await and only looks at the socket.

Related: the review on #197 covered reconnecting an established connection; this is the pending-handshake case. A fix with regression tests follows.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions