Skip to content

TSan: VolumeMeter paintEvent reads level/ballistics data without dataMutex #131

Closed

Description

@zackees

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' (audio capture, via volmeter callback):
    #0 VolumeMeter::setLevels              frontend/components/VolumeMeter.cpp:376  (currentLastUpdateTime, under dataMutex)
    #3 signal_levels_updated               libobs/obs-audio-controls.c:203
  Previous read by main thread (no lock):
    #0 VolumeMeter::detectIdle             frontend/components/VolumeMeter.cpp:508
    #1 VolumeMeter::paintEvent             frontend/components/VolumeMeter.cpp:750

WARNING: ThreadSanitizer: data race
  Write of size 4 by thread T49 (under dataMutex):
    #0 VolumeMeter::calculateBallisticsForChannel  frontend/components/VolumeMeter.cpp:556  (displayInputPeakHold)
    #2 VolumeMeter::setLevels                      frontend/components/VolumeMeter.cpp:386
  Previous read by main thread (no lock):
    #0 VolumeMeter::paintEvent             frontend/components/VolumeMeter.cpp:859

Cause

setLevels() runs on the audio capture thread and writes currentLastUpdateTime, current* and (through calculateBallistics) all display* arrays under dataMutex. paintEvent and detectIdle read them on the UI thread without the lock, and detectIdle → resetLevels() also writes them unlocked. The effects are torn meter values and a peak-hold indicator that flickers or resets wrongly.

Fix direction

Take dataMutex and copy a snapshot of the levels at the top of paintEvent, then draw from the copy. Do the idle check under the same lock.

Activity

  1. added
    bug
    on Oct 10, 2026
  2. zackees commented on Oct 13, 2026

    @zackees
    MemberAuthor

    Claiming: VolumeMeter paint/audio data race.

    1. Add a Qt-free concurrency test for the exact idle/reset and four-value channel snapshot helpers, and show ThreadSanitizer RED against unlocked stubs.
    2. Use those helpers in VolumeMeter so the UI snapshots under dataMutex and idle reset holds the same mutex as the audio callback.
    3. Run targeted TSan, lint and local gate, then open one PR to master. First PR expected today.
  3. added
    claimed
    on Oct 13, 2026
  4. zackees commented on Oct 13, 2026

    @zackees
    MemberAuthor

    Fixed by PR #442, merged as 5ba1b04. The UI now snapshots all four meter values under dataMutex, and the idle check/reset uses that same mutex. A Qt-free concurrency test was TSan RED before locking and GREEN after; lint, OFF/ON unit tests, and a full Linux Qt app build passed. No remaining work is known for the reported meter race.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugclaimed

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions