Skip to content

comma: don't free the decoder and sockets under a receive loop that is still starting - #286

Open
ehoeve786 wants to merge 1 commit into
softwiredtech:mainfrom
ehoeve786:fix/comma-receive-loop-race
Open

ehoeve786 wants to merge 1 commit into
softwiredtech:mainfrom
ehoeve786:fix/comma-receive-loop-race

Conversation

@ehoeve786

Copy link
Copy Markdown
Collaborator

The native stop only waits while receiveLoopExited is false, and the loop sets that only once it runs. A disconnect that landed before the loop thread entered nativeStartReceiveLoop (Android: connect() on Dispatchers.IO; iOS: the DispatchQueue.global block) returned at once, the decoder, sockets and context were freed, and the loop then started on them (use-after-free).

Android: connect() refuses to start once closed, and disconnect() keeps calling nativeStopReceiveLoop until connect's loop has returned before freeing anything. iOS: the same with a semaphore signalled when the background loop ends (not compiled here; no Xcode on this machine).

Testing

  • Android builds and the unit tests pass.
  • Not run on a device: this path needs a comma device on the same network, which my setup doesn't have connected.

🤖 Generated with Claude Code

…s still starting

The native stop only waits while receiveLoopExited is false, and the loop
sets that only once it runs. A disconnect that landed before the loop thread
entered nativeStartReceiveLoop (Android: connect() on Dispatchers.IO; iOS:
the DispatchQueue.global block) returned at once, the decoder, sockets and
context were freed, and the loop then started on them (use-after-free).

Android: connect() refuses to start once closed, and disconnect() keeps
calling nativeStopReceiveLoop until connect's loop has returned before
freeing anything. iOS: the same with a semaphore signalled when the
background loop ends (not compiled here; no Xcode on this machine).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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