Fixed data track streams dropping frames that arrive just before the end - #1025
Merged
davidliu merged 1 commit intoSep 16, 2026
Merged
Conversation
A collector that subscribed just before a short drain finished read the drained flag as set and emitted its own terminator ahead of the frames and terminator already buffered for it, so collection ended without them. The drain now shares its items with a replay of one: a collector receives the replayed item atomically with its subscription, which tells it whether a frame predates it or the stream had already ended.
adrian-niculescu
requested review from
MaxHeimbrock,
davidliu and
xianshijing-lk
as code owners
September 16, 2026 11:13
🦋 Changeset detectedLatest commit: b2dd327 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Merged
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.
Collecting a subscribed data track's
flowcan complete without delivering anything: when the last frames and the end of the stream arrive right as collection starts, the collector sometimes gets none of them.DataTrackStreamTest.everyFrameSurvivesTheEndOfStreamfails intermittently on main for this reason (1 of 30 runs here).The drain sets
drainedand then emits its terminator, andonSubscriptionemits a terminator of its own when it readsdrainedas set. A collector that subscribes just before a short drain finishes already has the frames and the terminator buffered, but itsonSubscriptioncheck runs after the flag was set, so its own terminator reachestakeWhilefirst. Pausing 5 ms at the start of thatonSubscriptionmakes every collection in the test come back empty.The flag can't tell a collector whether the drain ended before or after it subscribed, but the replay cache can: a collector receives the replayed item atomically with its subscription. The drain now shares wrapped items with
replay = 1, emittingStarted, the frames, thenEnded. A replayed frame predates the collector and is skipped, and a replayedEndedcompletes collection right away, which covers the late collector the flag was there for. The cost is that the replay cache holds the latest frame until the next item replaces it.With the same 5 ms pause, the test class passes, and without it, it passed 30 runs in a row.