Fix source manager lifetime race - #1772
Merged
Merged
Conversation
aleksandr-voitenko
force-pushed
the
fix-source-manager-lifetime-race
branch
from
September 9, 2026 21:51
4935d67 to
822ed2b
Compare
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Private scenes can retain weak references indefinitely because their allocation path lacks destroy-signal registration.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Fixes a race between source-property lookup and final source release.
Changes:
- Retains weak source references and promotes them safely.
- Prevents duplicate source registrations.
- Adds deterministic lifecycle regression tests.
File summaries
| File | Description |
|---|---|
obs-studio-server/source/osn-source.hpp |
Adds weak-reference lifecycle management. |
obs-studio-server/source/osn-source.cpp |
Uses safe promotion in GetProperties. |
obs-studio-server/tests/test-osn-source.cpp |
Tests both race outcomes. |
Review details
- Files reviewed: 3/3 changed files
- Comments generated: 1
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
summeroff
approved these changes
Sep 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fix a source lifetime race when reading OBS source properties concurrently with the source’s final release.
Motivation
GetPropertiescould retrieve a rawobs_source_t *shortly before OBS destroyed its reference control block. Attempting to acquire a strong reference through that stale pointer could crash the backend, as observed in the concurrent browser-source test on macOS.Context
Locking the source manager around the raw-pointer lookup was insufficient because the manager did not retain an OBS reference. The source could begin destruction before the manager received its destroy callback.
The manager now retains a weak OBS reference for each registered source.
GetPropertiespromotes that weak reference to a strong reference while holding the manager lock. If destruction has already started, it returnsInvalidReference.Implementation details
free()andclear().GetProperties.InvalidReference.Types of changes