fix: guard playTo() against reset() nulling the iterator mid-await - #46
Open
PriyeshPandey2000 wants to merge 2 commits into
Open
fix: guard playTo() against reset() nulling the iterator mid-await#46PriyeshPandey2000 wants to merge 2 commits into
PriyeshPandey2000 wants to merge 2 commits into
Conversation
reset() (called synchronously on play->pause) nulls this.iterator without acquiring playTo's mutex, so it can race an in-flight decode and throw "Cannot read properties of null (reading 'next')". Snapshot the iterator per loop iteration and re-check identity after each await instead of trusting the mutable field directly. Add a vitest regression test reproducing the race.
|
@PriyeshPandey2000 is attempting to deploy a commit to the Diffusion Studio Team on Vercel. A member of the Team first needs to authorize it. |
1 task
The iterator identity checks miss two windows: a playTo queued behind the mutex, and one suspended on the reseed branch's iterator.return(). In both the iterator is null before and after the reset, so identity cannot detect it, and playTo goes on to reseed a decode and schedule audio for a clip the user already paused. Track a generation counter bumped on every reset() and bail whenever it moves while playTo is suspended.
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.
Summary
AudioDecoder.playTo()holds anAsyncMutex, butreset()(called synchronously by the playback system on play→pause) nullsthis.iteratorwithout acquiring it. Ifreset()lands mid-await insideplayTo's decode loop, the resumed iteration reads a nulled iterator and throwsTypeError: Cannot read properties of null (reading 'next').this.iteratorper loop iteration and re-check its identity after eachawaitbefore trusting it, instead of reading the mutable field directly across suspension points.vitestas a dev dependency topackages/runtimeonly; happy to drop the test/dependency if you'd rather not introduce a test runner yet, the code fix stands on its own either way.Repro
Play a clip, pause mid-decode. The realtime engine drives
playbackSystemsynchronously offrequestAnimationFramewithout awaitingplayTo's promise, soreset()on the next tick can land while a previous tick'splayTois still suspended on an in-flight decode , timing-dependent, but the window exists on every frame where playback is paused mid-decode.Test plan
cd packages/runtime && npx vitest run— 2/2 pass