Repository navigation
Description
Summary
On Linux with PulseAudio, audio_monitor_reset tears down the working monitor before it knows the replacement can be created. If creating the replacement fails (server restart, sink missing, sink query error), monitoring silently stops and the monitor is left holding a freed resampler and device string, still registered with the audio system. Destroying it later frees them again and releases the PulseAudio wrapper reference a second time. Severity: medium. It needs a failed reset, but the result is lost monitoring plus a crash or heap corruption on the next destroy.
Steps / trigger
- On Linux with PulseAudio, enable audio monitoring on a source.
- Trigger a reset while creating the replacement will fail: call
obs_reset_audio_monitoring(), or remove the sink so a sink event triggers one, at a moment when the server query or the new playback connection fails. - Monitoring stops. Disabling monitoring on the source, or shutting down, then destroys the monitor with dangling pointers.
Cause
Line numbers are against current master.
libobs/audio-monitoring/pulse/pulseaudio-output.c:598:audio_monitor_resetcallsaudio_monitor_free(monitor)first.:554-570:audio_monitor_freeremoves the capture callback, destroys the resampler (:562), stops the stream (:565-566), drops a wrapper reference (:567) and freesdevice(:569). It does not clearresamplerordevice.:601,:604-609: the new monitor is built after that. Ifaudio_monitor_initfails, the old monitor is left as freed and nothing replaces it.:612-615:audio_monitor_destroyrunsaudio_monitor_freeon the same monitor again. That destroys the resampler and freesdevicea second time and callspulseaudio_unref()again.libobs/obs.c:2997(obs_reset_audio_monitoring) andpulseaudio-output.c:499-500(sink events) are the callers that reach the reset.
The backend has no Rust counterpart, so ON and OFF behave the same.
Proposed fix
Create the replacement monitor before releasing the old one: on success release the old monitor and publish the new one, on failure keep the working old monitor (resampler, stream and capture callback) untouched. Also retire and recreate a PulseAudio context that has gone failed or terminated when the wrapper is initialised, otherwise a replacement cannot succeed while other monitors still hold wrapper references. If the old stream has already detached when the replacement fails, release it fully and leave an empty, ignored monitor that is safe to retry or destroy. The regression test replaces the libpulse calls and covers a healthy-context failure, failed and terminated contexts, two monitors sharing a failed context, and a terminal context with a failed replacement.
I'd like to work on this; a fix with a regression test is ready.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
zackees commentedon Oct 13, 2026
@chriscoveries go ahead: please open the PR with the RED test commit first, then the fix (one PR per issue, targeting master). Marking it claimed for you so nobody duplicates it.
chriscoveries commentedon Oct 14, 2026
Releasing this one. We're backed up on CI and won't get it landed soon, so anyone who wants it is welcome to take it.
If it helps, our RED test and fix are on the fork branch
fix/pulse-monitor-reset-failure. They passed review on our side but haven't been through CI, so reuse them or start fresh, whichever you prefer.zackees commentedon Oct 14, 2026
Claiming.
libobs: keep the live PulseAudio monitor when reset fails (#486) (#713)