You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Found by the TSan launch pass (meta issue linked as parent). Upstream OBS code, unchanged in this fork.
Race
WARNING: ThreadSanitizer: data race
Write of size 8 by thread T49 'threaded-ml' (PulseAudio capture, holding the source's audio_buf_mutex):
#0 reset_audio_data libobs/obs-source.c:1505 (source->audio_ts = os_time)
#1 source_output_audio_place libobs/obs-source.c:1553
#3 obs_source_output_audio libobs/obs-source.c:4100
Previous read of size 8 by thread T8 'audio-io: audio':
#0 obs_source_audio_render libobs/obs-source.c:5512 (if (!source->audio_ts))
#1 audio_callback libobs/obs-audio.c:624
WARNING: ThreadSanitizer: data race
Write of size 8 by thread T49 (holding audio_buf_mutex):
#0 deque_push_back libobs/util/deque.h:147
#1 source_output_audio_push_back libobs/obs-source.c:1587
Previous read of size 8 by thread T8 (holding only obs->data.audio_sources_mutex):
#0 audio_buffer_insufficient libobs/obs-audio.c:443 (source->audio_input_buf[0].size)
#1 mark_invalid_sources libobs/obs-audio.c:472
Cause
Capture threads update audio_ts and audio_input_buf[] while holding source->audio_buf_mutex. The audio thread reads both in obs_source_audio_render and audio_buffer_insufficient without taking that mutex. It holds only audio_sources_mutex, which the capture thread never takes. These are real, unsynchronized 64-bit accesses. On x86-64 they are usually torn-free, but they're still UB and can give inconsistent size/audio_ts pairs when a timestamp jump resets the buffer mid-mix.
Repro
TSan build (-fsanitize=thread), headless launch with the default Desktop Audio/Mic sources under PulseAudio/PipeWire. Both races fire within seconds.
Fix direction
Read these fields under audio_buf_mutex, or make audio_ts atomic and snapshot the buffer size under the lock. Add a Tier 1/2 test that drives obs_source_output_audio from one thread against the mix loop from another, so the regression shows up under TSan.
Claiming: audio capture/mix synchronization. 1. Reproduce the unlocked timestamp/buffer reads with a regression against the real source and mixer path. 2. Protect the shared state while preserving render callback behavior. 3. Validate focused concurrency tests, sanitizer evidence, and the OFF/ON compatibility gates; open one PR after RED/GREEN evidence.
PR #662 is open. RED94909f355 reproduces the capture/mixer deque race under TSan. The fix synchronizes timestamp and buffer access, including transition child timestamps. Both real capture and active-transition cases pass TSan, 100 repetitions each OFF/ON pass under Xvfb, 192 C tests each pass, symbols match, and all local gate lanes passed on the stamped pushed head. CI is running before merge.
Fixed by #662. Capture, source rendering, buffering decisions, and transition timestamp reads now synchronize on audio_buf_mutex. The real capture/mixer regression was RED under TSan and is GREEN for direct capture and active transitions. 100 consecutive runs passed in each OFF/ON configuration; all local gate lanes and native macOS/Windows CI checks passed. The issue’s timestamp and input-buffer races are addressed.
Activity
zackees commentedon Oct 13, 2026
Claiming: audio capture/mix synchronization. 1. Reproduce the unlocked timestamp/buffer reads with a regression against the real source and mixer path. 2. Protect the shared state while preserving render callback behavior. 3. Validate focused concurrency tests, sanitizer evidence, and the OFF/ON compatibility gates; open one PR after RED/GREEN evidence.
zackees commentedon Oct 14, 2026
PR #662 is open. RED94909f355 reproduces the capture/mixer deque race under TSan. The fix synchronizes timestamp and buffer access, including transition child timestamps. Both real capture and active-transition cases pass TSan, 100 repetitions each OFF/ON pass under Xvfb, 192 C tests each pass, symbols match, and all local gate lanes passed on the stamped pushed head. CI is running before merge.
zackees commentedon Oct 14, 2026
Fixed by #662. Capture, source rendering, buffering decisions, and transition timestamp reads now synchronize on audio_buf_mutex. The real capture/mixer regression was RED under TSan and is GREEN for direct capture and active transitions. 100 consecutive runs passed in each OFF/ON configuration; all local gate lanes and native macOS/Windows CI checks passed. The issue’s timestamp and input-buffer races are addressed.
test: Reproduce capture/mixer audio buffer race under TSan (obs-rust#130
fix: Synchronize capture and mixer audio state (obs-rust#130 GREEN)
fix: Snapshot capture timestamps during transition mixing (obs-rust#130)
libobs: Move the transition clock and fit into obs-source-transition-…
libobs: Move the transition clock and fit into obs-source-transition-…
obs-source: Port the transition clock and fit (obs-rust#2055)
libobs: Move the transition render and audio steps into obs-source-tr…
libobs: Move the transition render and audio steps into obs-source-tr…
libobs: Move the transition render and audio steps into obs-source-tr…
obs-source: Port the transition render and audio steps (obs-rust#2184)
libobs: Move the source audio render mix plan into obs-source-audio-r…
obs-source: Port the source audio render mix plan (obs-rust#2254)