refactor: split the context state to render and control threads - #1239
Open
mdydek wants to merge 3 commits into
Open
refactor: split the context state to render and control threads#1239mdydek wants to merge 3 commits into
mdydek wants to merge 3 commits into
Conversation
WPT non-regression comparisonPASS — no regressions · 2 improved section(s) · overall 2586 → 2632 (+46)
Unchanged sections (26)
Baseline: Workflow run · this comment is updated on every push. |
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.
Problem
Only js state:
resume() flips the single state to RUNNING synchronously. The actual driver open is async and takes a few ms (Oboe/AVAudioSession — normal, not a failure). JS calls suspend() in that window. The guard reads RUNNING (not SUSPENDED), so it correctly decides to call audioPlayer_->suspend() — but the stream hasn't finished opening yet, so there's nothing real to stop. The stop call lands on a half-initialized stream (no-op, or worse, undefined behavior depending on the SDK); the open then completes moments later and audio starts playing — after suspend() already resolved and JS believes the context is suspended.
Only audio-thread state:
JS calls ctx.close() twice back-to-back (e.g. a cleanup effect firing twice). The "already closed" guard reads the engine-confirmed value, which hasn't updated yet because the engine hasn't processed either call. Both calls pass the guard and both proceed to release the same driver resources — double-free/double-release.
Solution
Two unrelated states, one serves as the guard for the unlogic calls, the second one guards internal audio engine to not call two things at the same time