Skip to content

obs-websocket: GetStats CPU usage shares one unlocked state across clients (data race, wrong values) #1346

Closed

Description

@vpacher

Part of #1285 (#1273). Correctness, found during the polling audit.

All clients share one os_cpu_usage_info_t (plugins/obs-websocket/src/obs-websocket.cpp:64). os_cpu_usage_info_query() writes its "last" fields on every call, without a lock, and requests run in parallel on the QThreadPool.

  • Two clients that poll at the same time cause a data race. C: libobs/util/platform-nix.c.h:100. Rust: rust/obs-util/src/ffi/platform_nix.rs:453 makes a &mut from the shared pointer, which is UB when two threads do it.
  • Without the race, each client still gets the CPU usage since the last call from any client, not since its own last call.
  • times() counts at 100 Hz, so two calls within 10 ms return 0.0.

Found by reading the code, not reproduced yet.

Fix: a mutex around the query in obs-websocket, or one CPU usage state per session.

Test: two threads that call the GetStats CPU query in parallel (TSan clean), and two sessions that poll at different rates each get the usage over their own interval.

Activity

  1. rdoupe commented on Oct 18, 2026

    @rdoupe
    Collaborator

    Claiming: I'll give each websocket session its own CPU usage state, with a lock (requests from one client can also run in parallel). Requests without a session, from the vendor API, use the shared state behind the same kind of lock. A regression test goes in obs-studio's cmocka suite with the submodule bump: parallel GetStats calls under TSan, plus two sessions polling at different rates.

  2. added
    claimed
    on Oct 18, 2026
  3. rdoupe commented on Oct 20, 2026

    @rdoupe
    Collaborator

    Still on this: the fix is obs-rust/obs-websocket#19 (CI green, mergeable, waiting for review). The obs-studio side, the submodule bump with test_ws_cpu_usage and the ledger line, is ready on a branch and opens as soon as #19 merges.

  4. removed
    claimed
    on Oct 22, 2026
  5. rdoupe commented on Oct 24, 2026

    @rdoupe
    Collaborator

    Claiming: #1346. The fix landed through the obs-websocket bump in #1996; I'm adding the regression test that shows it.

  6. added
    claimed
    on Oct 24, 2026
  7. added a commit that references this issue on Oct 24, 2026
    3ef31d4
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

    claimed

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions