Skip to content

fix: prevent live audio loss during close - #273

Open
mayankbohradev wants to merge 1 commit into
AssemblyAI:masterfrom
mayankbohradev:fix/live-session-close-race
Open

mayankbohradev wants to merge 1 commit into
AssemblyAI:masterfrom
mayankbohradev:fix/live-session-close-race

Conversation

@mayankbohradev

Copy link
Copy Markdown

Summary

Fix a race that can drop audio when a threaded live session closes while another thread is writing audio.

Impact

This affects sync transcription and dictation live sessions that accept audio from callback threads. If close() runs after write() checks the session state but before it queues the audio, the close marker can reach the uploader first. The uploader then stops. The write can still return successfully, but its audio is lost.

The race affects writes that overlap with close() or abort(). Normal sequential writes are not affected. The async dictation session is not affected.

Changes

  • Add a lock to order queue writes with the close and abort markers.
  • Check the session state again after converting the audio.
  • Raise RuntimeError if close wins before the write queues its audio.
  • Update the method documentation to explain brief lock contention.
  • Add event-controlled regression tests for sync and dictation sessions.

Tests

  • pytest tests/unit/test_sync_live.py tests/unit/test_dictation.py -q — 122 passed.
  • tox -e py312-latest — 744 passed.

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