Skip to content

fix: move pendingExitDraining access to main thread in onReconnecting#59

Merged
chrisuthe merged 1 commit intomainfrom
fix/onreconnecting-thread-safety
Mar 8, 2026
Merged

fix: move pendingExitDraining access to main thread in onReconnecting#59
chrisuthe merged 1 commit intomainfrom
fix/onreconnecting-thread-safety

Conversation

@chrisuthe
Copy link
Copy Markdown
Owner

Summary

  • Fixes a data race in onReconnecting() where pendingExitDraining was written from the WebSocket IO thread, while all other accesses are on the main thread
  • Moves the pendingExitDraining = false assignment into the mainHandler.post block
  • enterDraining() remains outside the post block since it is already thread-safe (guarded by SyncAudioPlayer.stateLock), preserving the intent that disconnect handlers immediately see DRAINING state

Test plan

  • Verify reconnection behavior: disconnect server, confirm audio drains from buffer and resumes after reconnect
  • Verify no race conditions: rapidly toggle network connectivity during playback

The onReconnecting() callback runs on the WebSocket IO thread, but
pendingExitDraining is a plain boolean only accessed from the main
thread everywhere else. Writing it from the IO thread is a data race.

Move the pendingExitDraining = false assignment into the mainHandler.post
block where all other accesses occur. The enterDraining() call remains
outside the post block since it is already fully thread-safe (guarded by
SyncAudioPlayer.stateLock), preserving the intent that disconnect
handlers immediately see DRAINING state.
@chrisuthe chrisuthe merged commit 7aa1dc1 into main Mar 8, 2026
@chrisuthe chrisuthe deleted the fix/onreconnecting-thread-safety 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