Skip to content

audit gap: obs-websocket GetStats/threads and remaining capture plugins not yet read for polling #1285

Closed

Description

@zackees

Part of #1273. Audit gap.

Not covered by the first pass of the audit:

  • plugins/obs-websocket (submodule empty in the audit checkout): GetStats and its stats and event threads. Check how often they sample CPU, memory, disk and render stats, which thread they run on, and whether many clients or high event subscription rates multiply the work.
  • linux-pipewire, linux-capture, mac-capture, vlc-video, decklink and text-freetype2 were only grepped for loop patterns (nothing found apart from os_event_try exits in mac-window-capture and the ffmpeg muxers), not read in depth.

To do: read them with the same criteria as #1273 (busy-spin / ~0 interval, UI-thread work, error-path spins) and file sub-issues for anything found.

Activity

  1. vpacher commented on Oct 17, 2026

    @vpacher
    Member

    Claiming the obs-websocket part only (GetStats, the stats and event threads, and how many clients or high event subscription rates multiply the work). The capture plugins in this issue stay open for someone else. Plan: read the code with the #1273 criteria (busy-spin or ~0 interval, UI-thread work, error-path spins), post the findings here, and open a sub-issue for each real finding.

  2. added
    claimedAn agent or person has claimed this; check the claim comment before starting
    on Oct 17, 2026
  3. vpacher commented on Oct 17, 2026

    @vpacher
    Member

    Findings for the obs-websocket part (submodule at 0d663ee). I read it with the #1273 criteria. There is no busy-spin and no ~0 interval. I found three problems: one UI-thread deadlock, one pool stall on a hung disk path, and one data race in GetStats. I did not reproduce them, the evidence is from reading the code.

    1. Server Stop() on the UI thread can deadlock (UI stall).
    WebSocketServer::Stop() calls _threadPool.waitForDone() and then waits in a 10 ms sleep loop until _sessions is empty (WebSocketServer.cpp:202-206). It runs on the UI thread when the settings dialog restarts the server (SettingsDialog.cpp:218) and at module unload (obs-websocket.cpp:141). Three requests wait on the UI thread from a pool thread with obs_queue_task(OBS_TASK_UI, ..., true): SetStudioModeEnabled (RequestHandler_Ui.cpp:70), SetCurrentSceneCollection and SetCurrentProfile (RequestHandler_Config.cpp:167, 259). The frontend runs those tasks with a blocking queued connection (OBSApp.cpp.hpp:1247). If one of these requests is in flight when Stop() starts, the pool thread waits for the UI thread and the UI thread waits for the pool, so OBS hangs. Also, the sleep loop reads _sessions.size() without _sessionMutex.
    Possible fix: do not wait for the pool on the UI thread (stop on a worker and finish from a callback), or make these requests use a non-blocking UI task and reply from it.

    2. GetStats queries free disk space on every call (pool stall).
    ObjectHelper::GetStats() calls os_get_free_disk_space() on the recording path for every request (Obs_ObjectHelper.cpp:40). This is the same call as #1282, but it runs on a pool thread, not the UI thread. On a hung network path each call blocks one pool thread. Clients that poll GetStats every second fill the pool (default size = ideal thread count). Event broadcasts use the same pool (WebSocketServer_Protocol.cpp:362), so all requests and events stop too.
    Possible fix: read the cached value from #1282 (#1336) when it is available, and report null or the last value while no fresh value exists.

    3. GetStats CPU usage: one shared state, no lock.
    All clients share one os_cpu_usage_info_t (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 pool. Two clients polling at the same time cause a data race (C: platform-nix.c.h:100; Rust: obs-util/src/ffi/platform_nix.rs:453 makes a &mut from the shared pointer, which is UB when two threads do it). Even without the race, each client gets the CPU usage since the last call from any client, not since its own last call. With times() at 100 Hz, two calls within 10 ms return 0.0.
    Possible fix: a mutex around the query in obs-websocket, or a CPU usage value per session.

    No problem found:

    • Volume meters: one handler shared by all clients (reference counted), created only while at least one client subscribes to InputVolumeMeters. It waits 50 ms on a condition variable and stops at once. More clients do not multiply the work.
    • Event broadcast: each event is serialized at most once per encoding (JSON, MessagePack), not once per client.
    • The settings dialog session table updates every 1 s only while the dialog is open.
    • The Sleep request is available only in batches, by design.
    • The server thread runs asio and blocks, it does not spin.

    I will open a sub-issue for each of 1, 2 and 3 unless you prefer to keep them here.

  4. vpacher commented on Oct 17, 2026

    @vpacher
    Member

    Sub-issues: 1 → #1344, 2 → #1345, 3 → #1346. The obs-websocket part of this audit is done; the capture plugins listed above are still open.

  5. zackees commented on Oct 17, 2026

    @zackees
    MemberAuthor

    Claiming the capture plugins part only (linux-pipewire, linux-capture, mac-capture, vlc-video, decklink, text-freetype2); @vpacher's obs-websocket part is done (#1344-#1346, thanks). I'm reading them with the #1273 criteria; findings become sub-issues of #1273.

  6. github-actions commented on Oct 17, 2026

    @github-actions

    Claim bot: @zackees, this is already claimed by vpacher. Pick something else or offer help here; once the claim goes stale, comment Taking over stale claim from @vpacher.

  7. zackees commented on Oct 17, 2026

    @zackees
    MemberAuthor

    Capture plugins part done (linux-pipewire, linux-capture, mac-capture, vlc-video, decklink, text-freetype2), read at origin/master with the #1273 criteria. No busy-spin and no ~0 interval. Three findings, filed as sub-issues of #1273:

    Minor notes, not filed:

    Checked and fine:

    • linux-pipewire: reconnect backoff (250 ms doubling to 10 s, then 30 s), portal timers, and buffer dequeue.
    • text-freetype2: one os_stat per second per source.
    • mac-capture: find_window throttled to 500 ms, the window-capture worker on an event, and SCK enumeration only at create/update.
    • vlc-video: waits clamped and one-shot.
    • decklink (non-SDK): callback-driven, no polling.

    With @vpacher's obs-websocket part (#1344-#1346) this covers the whole issue.

  8. zackees commented on Oct 17, 2026

    @zackees
    MemberAuthor

    Both parts of the audit gap are read; findings are sub-issues of #1273.

  9. zackees commented on Oct 27, 2026

    @zackees
    MemberAuthor

    Cross-reference: #1344 (blocking OBS_TASK_UI tasks can deadlock obs-websocket Stop()) is closed as an upstream limitation of the preserved C++ plugin, not a Rust OBS defect. The deadlock is between the plugin's pool thread and its own Stop() on the UI thread; every fix would either modify the frozen plugin or leave a queued task pointing at a caller stack frame that has already unwound. Keeping it here so a future upstream fix is picked up when the plugin is next re-synced.

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

    claimedAn agent or person has claimed this; check the claim comment before starting

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions