PipeWire backend: process() can run before the local port exists — null port token, segfault in release builds - #249
Closed
ryanatseolaudio wants to merge 1 commit into
Closed
ryanatseolaudio wants to merge 1 commit into
ryanatseolaudio wants to merge 1 commit into
Conversation
The filter can start before the local port exists (open sequence) or run after the port was removed (close sequence). With no valid port token there is no buffer to process; skip instead of dereferencing a null token. With asserts compiled out (release build) the old code segfaulted (pw.filter_dequeue_buffer on a null token).
Member
|
thanks for the PR ! checking that |
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.
Environment: libremidi @ 8b12bce · libpipewire 1.0.5 · Ubuntu 24.04.4 LTS
What happens:
midi_in_pipewire::process() (and the out/UMP variants) can run while this->port is not a valid token:
PipeWire data loop may fire process() — and only then does create_local_port() (midi_in.hpp:55) set this->port. A
process() in that window calls pw.filter_dequeue_buffer(this->port.opaque) with port.opaque == nullptr.
Symptoms:
at shutdown (close path). The shutdown variant is intermittent (~1-in-3 on our machine).
Repro: open/close PipeWire midi_in/midi_out ports repeatedly (e.g. an app that creates and destroys ports at
startup); the open-path race is timing-dependent and appeared after repeated cycles.
Proposed fix:
Early-return in all four process() implementations (pipewire in/out, pipewire_ump in/out) when the filter or port
token is invalid:
We ran some initial testing on this guard and it seems to eliminate both the startup and shutdown aborts in
debug and release.