Drain the callback pipe on stream stop#199
Open
padenot wants to merge 1 commit into
Open
Conversation
audioipc2 services each stream over two independent IPC pipes, each on its own thread per side: the control pipe (StreamStop/StreamStopped) and the callback pipe (CallbackReq::Data/CallbackResp::Data). There is no ordering guarantee between them, so a data callback already queued on the callback pipe can be delivered to the client after StreamStopped has come back on the control pipe — i.e. after cubeb_stream_stop() has returned. This violates cubeb's contract that no data callback runs after stop. The fix is to add CallbackReq::Drain / CallbackResp::Drain. After stopping the native stream, the server makes a *synchronous* Drain call on the callback pipe before replying StreamStopped. The client services that pipe on a single thread in receive order, so by the time it answers Drain every earlier data callback has already run to completion and returned. The call must stay blocking: a fire-and-forget Drain would not order anything and would reintroduce the race. This guarantee is specific to data callbacks, which users rely on to synchronize shutdown sequences.Sstate and device change callbacks aren't affected by this fix and aren't a problem.
222aee1 to
8b6c39e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
audioipc2 services each stream over two independent IPC pipes, each on its own thread per side: the control pipe (StreamStop/StreamStopped) and the callback pipe (CallbackReq::Data/CallbackResp::Data). There is no ordering guarantee between them, so a data callback already queued on the callback pipe can be delivered to the client after StreamStopped has come back on the control pipe — i.e. after cubeb_stream_stop() has returned. This violates cubeb's contract that no data callback runs after stop.
The fix is to add CallbackReq::Drain / CallbackResp::Drain. After stopping the native stream, the server makes a synchronous Drain call on the callback pipe before replying StreamStopped. The client services that pipe on a single thread in receive order, so by the time it answers Drain every earlier data callback has already run to completion and returned. The call must stay blocking: a fire-and-forget Drain would not order anything and would reintroduce the race.
This guarantee is specific to data callbacks, which users rely on to synchronize shutdown sequences.Sstate and device change callbacks aren't affected by this fix and aren't a problem.