mozilla / cubeb

Cross platform audio library
ISC License
434 stars 123 forks source link

Data Callback executed after stream stop on alsa backend with pipewire-alsa #762

Open git-bruh opened 9 months ago

git-bruh commented 9 months ago

Hello, I've discovered a bug where the stream's data callback gets called even after alsa_stream_stop has been called. This in-turn causes a crash in Firefox when it tries to capture the microphone from it's WebRTC component (happens very rarely). I've traced it down to cubeb. This does not seem to be reproducible with the example program from the docs

Still debugging it, will keep updating here with more details

More details: https://bugzilla.mozilla.org/show_bug.cgi?id=1859796

git-bruh commented 9 months ago

I haven't verified this, but do you think there's a possibility that the calls to alsa_set_stream_state in alsa_stream_stop and alsa_run could be "racing" due to interleaved calls to mutex locks and unlocks?

So even tho the calls are wrapped in mutexes, it might happen that alsa_stream_stop sets the state to INACTIVE, and it subsequently gets set to PROCESSING by the other thread after that thread locks the mutex