Skip to content

fix(streaming,realtime): cancel a pending connect() when close() is called - #192

Open
RaphaelFakhri wants to merge 1 commit into
AssemblyAI:mainfrom
RaphaelFakhri:fix/streaming-close-during-connect
Open

RaphaelFakhri wants to merge 1 commit into
AssemblyAI:mainfrom
RaphaelFakhri:fix/streaming-close-during-connect

Conversation

@RaphaelFakhri

Copy link
Copy Markdown

Summary

Cancel a pending connect() when close() is called, for both StreamingTranscriber and RealtimeTranscriber.

Problem

  • StreamingTranscriber.close() removes the socket but does not stop the retry loop in connect(). After the attempt times out, the loop opens a new socket, so a connection is created after close() returned. It can also resolve connect() on a transcriber the caller already closed.
  • RealtimeTranscriber.close() removes the socket listeners, so a pending connect() promise never settles.

Changes

  • StreamingTranscriber: close() increments a connect epoch and cancels the attempt in flight. connect() checks the epoch before each attempt and after each retry delay, and rejects with Connection closed before the session started. Calling connect() again after close() still works.
  • RealtimeTranscriber: close() rejects the pending connect() promise with the same message.
  • Bump the version to 4.41.6 and add the changelog entry that the version bump check requires.

Tests

New tests in tests/unit/streaming-close-during-connect.test.ts and tests/unit/realtime-close-during-connect.test.ts:

  • No new connection opens after close() while an attempt is pending.
  • No new connection opens when close() runs during the retry delay.
  • connect() can be called again after close().
  • RealtimeTranscriber.connect() rejects when close() is called before SessionBegins.

Before the change, all four fail. After the change, all four pass.

pnpm jest --config jest.unit.config.js --testTimeout 3000 tests/unit/streaming-close-during-connect tests/unit/realtime-close-during-connect

pnpm lint:eslint, pnpm lint:tsc and pnpm lint:format pass.

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.

1 participant