Fix AsyncIterableProducer.tee() to properly synchronize producers#298542
Open
kbhujbal wants to merge 1 commit intomicrosoft:mainfrom
Open
Fix AsyncIterableProducer.tee() to properly synchronize producers#298542kbhujbal wants to merge 1 commit intomicrosoft:mainfrom
kbhujbal wants to merge 1 commit intomicrosoft:mainfrom
Conversation
The previous implementation called `start()` without awaiting it inside
each executor, relying on implicit microtask ordering for correctness.
This was fragile and caused the empty source and error propagation test
cases to be skipped.
Restructure tee() to use an explicit `bothReady` deferred promise that
signals when both emitters are available, and a `done` deferred promise
that keeps the executors alive until source iteration completes. This
eliminates the fire-and-forget `start()` call and makes the data flow
explicit.
Also unskip the two previously skipped test cases ('tee - empty source'
and 'tee - handles errors in source') and remove the related TODO
comments from all four tee tests.
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.
Fixes a known implementation issue in
AsyncIterableProducer.tee()(added in #276037) wherestart()was called without being awaited inside executors, relying on implicit microtask ordering for correctness.Problem
The previous implementation used a fire-and-forget
start()call from each executor, with an early-return guard (if (!emitter1 || !emitter2) return). This was fragile — two test cases ('tee - empty source' and 'tee - handles errors in source') were skipped with a TODO noting the bug.Solution
Restructure
tee()to use explicit synchronization:bothReadydeferred promise that signals when both emitters are availabledonedeferred promise that keeps executors alive until source iteration completesbothReady.p.then(...)instead of a fire-and-forgetstart()callThis makes the data flow explicit and eliminates reliance on microtask ordering.
Test plan