Skip to content

fix: guard against TOCTOU race on syncAudioPlayer from WebSocket thread#60

Merged
chrisuthe merged 1 commit intomainfrom
fix/toctou-sync-audio-player
Mar 8, 2026
Merged

fix: guard against TOCTOU race on syncAudioPlayer from WebSocket thread#60
chrisuthe merged 1 commit intomainfrom
fix/toctou-sync-audio-player

Conversation

@chrisuthe
Copy link
Copy Markdown
Owner

Summary

  • In onAudioChunk (WebSocket thread), capture syncAudioPlayer into a local val before decoding and queuing, preventing the main thread from nulling/releasing it mid-call
  • Add isReleased early-return guard to SyncAudioPlayer.queueChunk() so calls on a released player are safely ignored
  • Add isReleased early-return guard to SyncAudioPlayer.enterDraining() for the same reason (called from onReconnecting on the WebSocket thread)

Test plan

  • Verify build compiles cleanly (assembleDebug passes)
  • Stress test: rapidly connect/disconnect while audio is streaming to exercise the race window
  • Confirm no crashes or IllegalStateException from AudioTrack after player release

@chrisuthe chrisuthe merged commit f989f3f into main Mar 8, 2026
In onAudioChunk, capture syncAudioPlayer into a local val before use
to prevent the main thread from nulling/releasing it between the null
check and the method call.

Add isReleased guards to SyncAudioPlayer.queueChunk() and
enterDraining() so that calls on a released player are safely ignored,
even when a stale reference is held by another thread.
@chrisuthe chrisuthe deleted the fix/toctou-sync-audio-player branch March 8, 2026 02:40
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