Skip to content

fix: add @Volatile to pendingExitDraining for thread safety#54

Merged
chrisuthe merged 1 commit intomainfrom
fix/volatile-pending-exit-draining
Mar 8, 2026
Merged

fix: add @Volatile to pendingExitDraining for thread safety#54
chrisuthe merged 1 commit intomainfrom
fix/volatile-pending-exit-draining

Conversation

@chrisuthe
Copy link
Copy Markdown
Owner

Summary

  • pendingExitDraining is written from the WebSocket IO thread (onReconnecting) and read/written from the main thread (onReconnected, completePendingExitDraining). Without @Volatile, the JVM has no memory visibility guarantee for the cross-thread access, which could cause a stale read and skip the exitDraining() call after reconnection.
  • Adds @Volatile annotation to ensure writes are immediately visible across threads, consistent with the existing @Volatile on syncAudioPlayer (line 123).

Test plan

  • Verified the project compiles with ./gradlew assembleDebug
  • Manual test: connect to a server, trigger reconnection, verify playback resumes correctly after reconnect

pendingExitDraining is written from the WebSocket IO thread in
onReconnecting() and read/written from the main thread in
onReconnected() and completePendingExitDraining(). Without @volatile,
the JVM provides no guarantee that the write on the IO thread is
visible to the main thread, which could cause a stale read and
skip the exitDraining() call after reconnection.
@chrisuthe chrisuthe merged commit 4db408f into main Mar 8, 2026
@chrisuthe chrisuthe deleted the fix/volatile-pending-exit-draining 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