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
{{ message }}
Repository navigation
obs-websocket: GetStats CPU usage shares one unlocked state across clients (data race, wrong values) #1346
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.
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.
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.
Activity
rdoupe commentedon Oct 18, 2026
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.
rdoupe commentedon Oct 20, 2026
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_usageand the ledger line, is ready on a branch and opens as soon as #19 merges.requesthandler: Measure GetStats CPU usage per session (#19)
rdoupe commentedon Oct 24, 2026
Claiming: #1346. The fix landed through the obs-websocket bump in #1996; I'm adding the regression test that shows it.
test: Cover GetStats CPU usage per session in obs-websocket (obs-rust…