Skip to content

frontend: Free disk space is queried off the UI thread (#1282) - #1336

Merged
zackees merged 3 commits into
masterfrom
fix/1282-disk-space-off-ui
Oct 17, 2026
Merged

zackees merged 3 commits into
masterfrom
fix/1282-disk-space-off-ui

Conversation

@zackees

@zackees zackees commented Oct 17, 2026 •

Copy link
Copy Markdown
Member

Refs #1282 (parent #1273). Refs, not Fixes: the real app has not been run against a hung network path yet; #1282 closes after that check. Features ledger line added (docs/features.md, Scenes and UI).

Cause

The recording timer (OBSBasic::CheckDiskSpaceRemaining, every 1 s while recording) and the stats window (OBSBasicStats::Update, every 2 s while it is visible) called os_get_free_disk_space() on the UI thread. On a hung network or NAS recording path, statvfs / GetDiskFreeSpaceEx can block for seconds, and the UI froze for that long.

Design

frontend/utility/disk-space-monitor.{hpp,cpp.hpp} is a Qt-free helper (its own unity group and PCH per BUILD.md) that owns one worker thread:

  • request(path) returns at once and coalesces requests: at most one query runs at a time, a request for the path already being queried is dropped, and a request for another path takes the single pending slot.
  • latest(path) returns {bytes, timestamp_ns (os_gettime_ns), valid} for the last finished query of that path. A value for one path is never reported for another.
  • The free-space function is injected; the default is os_get_free_disk_space.
  • Shutdown: the destructor sets stop and waits up to 250 ms for the worker to exit, then joins it. If the worker is still stuck in a hung query after that, the destructor detaches it. The worker holds its own shared_ptr to the state, so when the query finally returns it touches no freed memory and exits without starting another query.

How the UI uses it:

  • Recording: the running check calls request, then reads the value. It acts only on a value that finished after the recording started, with the threshold unchanged (RECORD_MIN_FREE_BYTES, same stop and message). It does nothing until such a value exists. The URL and no-path cases return early, as before.
  • Stats: shows the last value with the same units and colour classes. The label stays empty, as it was before the first update, until a value exists, and "disk full in" is skipped until then.
  • Unchanged: the one-shot check before a recording or replay buffer starts (RECORD_DISK_CHECK_START) is still synchronous.

Tests

test/cmocka/test_disk_space_monitor.cpp is new, registered through tests.d/test_disk_space_monitor.cmake. No existing test was edited. The injected free-space function blocks for 2 s. The test checks that:

  • request + latest return in under 10 ms, and the value appears once the query completes;
  • 50 requests while one query is in flight start only one query;
  • after a path change, latest(new) is invalid until the new path's value (222) arrives;
  • destroying the monitor during a hung query returns in under 1.5 s.

RED (449c3c3, a stub that runs the query synchronously on the caller's thread), rust/tools/linux-validate/run.sh --repeat 1 --tests test_disk_space_monitor: all 4 cases failed, and test_disk_space_monitor was the only failing test (286/287 passed).

GREEN (70fcf22), same command: 287/287 passed in both the libobs (OFF) and libobs-with-rust (ON) builds, and the --repeat runs passed too (8.4 s each).

Tier 3 and Tier 4 do not apply: this is frontend C++ with no Rust port and no protocol change.

Qt CI lane

The OBSBasic/OBSBasicStats edits are under frontend/, so ci/ci_scope.py selects the Linux Qt lane (ci/linux_qt_frontend.sh), which compiles and links the obs-studio Qt target. That build is the compile check for the UI call sites; I could not build the Qt frontend locally (no prebuilt Qt prefix here). The new test is not Qt-linked and runs in Tier 2. I have not run the real app with this change, so the behaviour on a hung NAS path is shown only by the unit test.

@zackees

zackees commented Oct 17, 2026

Copy link
Copy Markdown
Member Author

macOS Tier 2 failure here is test_ingest_refresh_wait (from #1326, a 150 ms bound too tight for a loaded macOS runner), not this PR; fix in #1338. Rerunning the failed job.

chriscoveries pushed a commit to chriscoveries/obsrust-fork that referenced this pull request Oct 17, 2026
… ms (obs-rust#1338)

test_ingest_refresh_wait (obs-rust#1326) required a 50 ms refresh to end the wait
within 150 ms; a loaded macOS runner overslept it (failed_refresh_ends_wait,
line 66, Tier 2 macos-26 on obs-rust#1336). What the test proves is that the wait
ends at the refresh and not at the 5000 ms timeout, so bound it at 1000 ms.

Refs obs-rust#1284, obs-rust#838
RED: DiskSpaceMonitor stub queries synchronously on the caller's thread.
DiskSpaceMonitor runs os_get_free_disk_space() on one worker thread,
coalescing requests; the recording timer and the stats window read the
last value instead of blocking on statvfs/GetDiskFreeSpaceEx.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant