Skip to content

libobs: Make the allocation count stable when obs_startup returns - #667

Merged
zackees merged 2 commits into
masterfrom
fix/663-startup-alloc-race
Oct 14, 2026
Merged

zackees merged 2 commits into
masterfrom
fix/663-startup-alloc-race

Conversation

@zackees

@zackees zackees commented Oct 14, 2026

Copy link
Copy Markdown
Member

Fixes #663

Root cause: os_set_thread_name (threading-posix.c) bstrdup'd and freed names longer than 15 chars, so each new thread (tiny_tubular_task_thread, libobs: hotkey thread) did a bmalloc/bfree pair on its own thread right after obs_startup returned. bnum_allocs() counts all threads, so a read straddling it is off by one. The hotkey thread also registered its profiler name lazily (profile_store_name/profile_register_root, also on Windows); it now does that and a first profiled pass before obs_hotkey init returns.

RED (commit 1): new test_startup_alloc_stable (100 startup/sleep/compare cycles) fails on Linux OFF: 355 != 356.
GREEN (commit 2): passes; run.sh --repeat 30 passes in OFF and ON, symbols IDENTICAL, local gate stamped.

Caveats: the Windows os_set_thread_name does not allocate, so the Windows flake is most likely the hotkey profiler registration (not reproduced locally). Rust os_set_thread_name already uses a stack buffer.

Refs #663. Fails on Linux with 355 != 356.
…EEN)

os_set_thread_name copied long names on the heap and freed them, so every new
thread (task queue, hotkey) allocated and freed right after obs_startup
returned. The hotkey thread also registered its profiler name lazily. Truncate
on the stack and let the hotkey thread finish its one-time work before
obs_hotkey_init returns.

Fixes #663

Local-Gate: v1 tree=5fce2f0cf801ee4e3897f29805119e7dd69542e5 secs=321 lanes=lint:run,rust-test:run,cross:run,tier2-linux:run
Ci-Attestation: {"at":1791942252,"gate":"rust/all/fmt","host":"linux-x86_64","key":"4ccc9a955868b5eb48993b04a528770925a6f7b6fc7007bcfa22e4f1033471f7","lane":"lint","parents":["4239f2becd49fe85c2edb6ae64ce5c31f59d6d12"],"secs":17,"stamp":"e182f1bdb22ec7913166d5acdbbf74d5","tree":"5fce2f0cf801ee4e3897f29805119e7dd69542e5","v":1,"via":"run"}
Ci-Attestation: {"at":1791942252,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"4ccc9a955868b5eb48993b04a528770925a6f7b6fc7007bcfa22e4f1033471f7","lane":"lint","parents":["4239f2becd49fe85c2edb6ae64ce5c31f59d6d12"],"secs":17,"stamp":"8ae5d41fe1cb111565bdd4936ee101cc","tree":"5fce2f0cf801ee4e3897f29805119e7dd69542e5","v":1,"via":"run"}
Ci-Attestation: {"at":1791942252,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"02b0ffb7168debf733d4237c7ae625430dab1c222c8bc16635474f9a894f0b5c","lane":"rust-test","parents":["4239f2becd49fe85c2edb6ae64ce5c31f59d6d12"],"secs":92,"stamp":"e7b4f244956c6bff433603b3a9133939","tree":"5fce2f0cf801ee4e3897f29805119e7dd69542e5","v":1,"via":"run"}
Ci-Attestation: {"at":1791942253,"gate":"rust/x86_64-pc-windows-msvc/clippy","host":"linux-x86_64","key":"85a2a9d93fbbc48f22bae2010da213b5724834c9cd9eaa62b2b55602b52706cc","lane":"cross","parents":["4239f2becd49fe85c2edb6ae64ce5c31f59d6d12"],"secs":67,"stamp":"35ad8014aed9067c4c3469f7a05fbb2b","tree":"5fce2f0cf801ee4e3897f29805119e7dd69542e5","v":1,"via":"run"}
Ci-Attestation: {"at":1791942253,"gate":"rust/x86_64-pc-windows-msvc/dylint","host":"linux-x86_64","key":"85a2a9d93fbbc48f22bae2010da213b5724834c9cd9eaa62b2b55602b52706cc","lane":"cross","parents":["4239f2becd49fe85c2edb6ae64ce5c31f59d6d12"],"secs":67,"stamp":"47a3303c79eb609707c6c41e0a135831","tree":"5fce2f0cf801ee4e3897f29805119e7dd69542e5","v":1,"via":"run"}
Ci-Attestation: {"at":1791942253,"gate":"rust/aarch64-apple-darwin/clippy","host":"linux-x86_64","key":"85a2a9d93fbbc48f22bae2010da213b5724834c9cd9eaa62b2b55602b52706cc","lane":"cross","parents":["4239f2becd49fe85c2edb6ae64ce5c31f59d6d12"],"secs":67,"stamp":"edb920ae1f42765689b9533401f032d1","tree":"5fce2f0cf801ee4e3897f29805119e7dd69542e5","v":1,"via":"run"}
Ci-Attestation: {"at":1791942253,"gate":"rust/aarch64-apple-darwin/dylint","host":"linux-x86_64","key":"85a2a9d93fbbc48f22bae2010da213b5724834c9cd9eaa62b2b55602b52706cc","lane":"cross","parents":["4239f2becd49fe85c2edb6ae64ce5c31f59d6d12"],"secs":67,"stamp":"6d170155ce3b3c952b87366671ec088b","tree":"5fce2f0cf801ee4e3897f29805119e7dd69542e5","v":1,"via":"run"}
Ci-Attestation: {"at":1791942253,"gate":"rust/x86_64-apple-darwin/clippy","host":"linux-x86_64","key":"85a2a9d93fbbc48f22bae2010da213b5724834c9cd9eaa62b2b55602b52706cc","lane":"cross","parents":["4239f2becd49fe85c2edb6ae64ce5c31f59d6d12"],"secs":67,"stamp":"705bf16f5f453f17c45bb94e356d7bb2","tree":"5fce2f0cf801ee4e3897f29805119e7dd69542e5","v":1,"via":"run"}
Ci-Attestation: {"at":1791942253,"gate":"rust/x86_64-apple-darwin/dylint","host":"linux-x86_64","key":"85a2a9d93fbbc48f22bae2010da213b5724834c9cd9eaa62b2b55602b52706cc","lane":"cross","parents":["4239f2becd49fe85c2edb6ae64ce5c31f59d6d12"],"secs":67,"stamp":"f837e37bcef505ea998340a286b5943f","tree":"5fce2f0cf801ee4e3897f29805119e7dd69542e5","v":1,"via":"run"}
Ci-Attestation: {"at":1791942253,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"f2511da20d1fd17bc5b14311db3eaa0bc6019d4fce219aa4b0ade2bddd6b3ce3","lane":"tier2-linux","parents":["4239f2becd49fe85c2edb6ae64ce5c31f59d6d12"],"secs":145,"stamp":"b4a34b2054769413405335cc5a6508d0","tree":"5fce2f0cf801ee4e3897f29805119e7dd69542e5","v":1,"via":"run"}
@zackees zackees added the ci-full Run every CI job on this PR, including the release-gating OBS app builds and Flatpak label Oct 14, 2026
@zackees

zackees commented Oct 14, 2026

Copy link
Copy Markdown
Member Author

The hotkey startup barrier addresses the concrete late-profiler initialization path recorded in #663. Please keep the existing C tests unchanged and obtain actual Windows OFF/ON Tier 2 GREEN before calling the Windows flake resolved.

The new regression test currently uses os_sleep_ms(30) to give the worker a chance to run. docs/rust-port/testing-policy.md explicitly requires threading tests to synchronize with events/semaphores/joins rather than sleeps, and 100 consecutive OFF/ON runs without a flake. A deterministic barrier/observable worker-progress regression would cover the allocation interval without relying on scheduler timing. The shown repeat30 is useful evidence but does not satisfy the required repeat100.

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

Labels

ci-full Run every CI job on this PR, including the release-gating OBS app builds and Flatpak

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

test: test_missing_files_list's first case is flaky on Windows (bnum_allocs off by one after obs_startup)

1 participant