Skip to content

libobs: Restore the global source wait mutex when a canvas goes away - #2581

Merged
zackees merged 3 commits into
masterfrom
fix/2547-canvas-mutex-restore
Oct 27, 2026
Merged

zackees merged 3 commits into
masterfrom
fix/2547-canvas-mutex-restore

Conversation

@zackees

@zackees zackees commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

Refs #2547

RED commit a22e993 adds a case to test/cmocka/test_canvas_destroy_scene_refs.c: a scene is moved to a second canvas, released (its deferred destroy queued), and both canvases are freed before obs_wait_for_destroy_queue() runs. M_PERTURB fills the freed canvas so a deferred destroy that still waits on the canvas mutex reads garbage. That is the #2547 crash: run 40454928969 job 122031355159 faulted in pthread_mutex_unlock from obs_source_destroy_defer, after both move canvases were destroyed.

GREEN commit 5130d0f restores context.mutex to the global source mutex when a source leaves a canvas name list (obs_canvas_remove_source) and for the sources a canvas is about to free (obs_canvas_destroy). The canvas mutex still protects the list while the source is in it. The barrier the deferred destroy needs is the global source mutex the video tick holds; the canvas mutex never was that barrier and dangles once the canvas is freed.

Commit 83c2f09 removes the #ifdef _WIN32 return 77 skip from test_scene_canvas_characterization.c so the characterization runs on Windows again.

Evidence: Linux Tier 2 on the ready PR passed all four shard jobs in both OFF and ON modes plus CI Gate (run 40474301087). The Windows lane showed as skipping for this PR, so the restored Windows characterization still needs a Windows Tier 2 run before this closes #2547. Local full gate not run for this revision (the Docker image build exceeded the local time budget), so PR CI is the verification path.

The characterization crash in #2547 was a source whose deferred destroy
waited on a mutex the canvas had already freed. Moving a scene to a second
canvas leaves that pointer on the destination, so freeing the canvases right
after the scene's last release has the destroy task read freed memory.
M_PERTURB fills the freed canvas so the lost pointer reads garbage. RED.
obs_context_wait() locks context->mutex, which obs_canvas_insert_source()
points at the canvas's name-list mutex. obs_canvas_destroy() frees that mutex
synchronously, so a source destroyed just before its canvas had its deferred
destroy read freed memory: the Windows Cargo core crashed in
pthread_mutex_unlock from obs_source_destroy_defer (#2547).

A source that leaves a canvas's name list is no longer protected by the canvas
mutex, and the barrier the deferred destroy needs is the global source mutex
the video tick holds. Restore it when obs_canvas_remove_source() takes the
source out of the list and when obs_canvas_destroy() walks the sources it is
about to free. The canvas mutex still protects the list while the source is in
it. GREEN.
The suite returned 77 (CTest's skip code) on Windows while #2547 diagnosed the
Cargo-core teardown crash. The stack is captured and the dangling canvas mutex
behind it is fixed, so run the characterization on Windows again and keep the
Linux assertions as they are.
@zackees
zackees marked this pull request as ready for review October 27, 2026 08:33
@zackees

zackees commented Oct 27, 2026

Copy link
Copy Markdown
Member Author

Status: all Linux lanes and CI Gate passed on the ready PR (run 40474301087), including both Tier 2 shard sets in OFF and ON modes. The Windows lane (Build / Windows) shows as skipping for this PR, so the restored characterization has not run on Windows yet. Needs a Windows Tier 2 run (merge queue or a labelled/manual run) before #2547 can close; the regression case itself runs in test_canvas_destroy_scene_refs (Linux-only registration) and passed in both shard sets. Master advanced 3 commits since the branch base; a coordinator rebase may be needed before queueing.

@zackees
zackees added this pull request to the merge queue Oct 27, 2026
@zackees

zackees commented Oct 27, 2026

Copy link
Copy Markdown
Member Author

Handed off to the coordinator: Linux lanes and CI Gate green, marked ready, auto-merge on. Refs (not Fixes) #2547 until a Windows Tier 2 run exercises the restored characterization.

Merged via the queue into master with commit 0b4a5ce Oct 27, 2026
36 checks passed
@zackees
zackees deleted the fix/2547-canvas-mutex-restore branch October 27, 2026 08:56
@obs-rust-project-manager obs-rust-project-manager Bot moved this from In progress to Done in obs-rust Multiview Oct 27, 2026
MCPVOT pushed a commit to MCPVOT/obs-studio that referenced this pull request Oct 30, 2026
…#2581 restored Windows (obs-rust#2586) (obs-rust#2587)

The header still said the whole executable was skipped on Windows until
obs-rust#2547 fixed the root cause. obs-rust#2581 removed that skip (the main() block
returning 77) along with the canvas mutex fix, and left the comment
behind, so the file contradicted its own code and pointed at a closed
issue. Describe the current behavior instead: skip code while obs-rust#2547
diagnosed, running again since obs-rust#2581. Comments only; no code change.

Co-authored-by: Zachary Vorhies <[email protected]>
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.

Restore Windows scene lookup characterization after Cargo-core teardown crash

1 participant