Fix testFlatBlockingMapOnto crashing on iOS simulator#3555
Merged
rnro merged 2 commits intoapple:mainfrom Mar 19, 2026
Merged
Conversation
Motivation * `testFlatBlockingMapOnto` sets up a `flatMapBlocking` chain that dispatches work to `DispatchQueue.global()`, but never waits for the chain to complete before returning. The `defer` block calls `syncShutdownGracefully()`, which shuts down the event loop while the GCD dispatch is still in-flight. When the GCD work completes and tries to deliver its result back to the event loop, it finds the loop already shut down, causing a crash. On fast machines the GCD work completes before shutdown, but on slow iOS simulators shutdown wins the race consistently. This crash also kills whichever other test happens to be running concurrently (typically `testRepeatedTaskThatIsCancelledAfterRunningAtLeastTwiceNotifies`). Modifications * Capture the `EventLoopFuture` from the `flatMapBlocking` chain and call `.wait()` on it before the function returns, ensuring the GCD dispatch delivers its result back to the event loop before shutdown begins. Move the assertions from the `.whenSuccess` closure to after the `.wait()`. Result * The event loop is no longer shut down while GCD work is in-flight, fixing the crash on iOS simulator CI.
0a21e27 to
433878d
Compare
glbrntt
approved these changes
Mar 19, 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.
Motivation
testFlatBlockingMapOntosets up aflatMapBlockingchain that dispatches work toDispatchQueue.global(), but never waits for the chain to complete before returning. Thedeferblock callssyncShutdownGracefully(), which shuts down the event loop while the GCD dispatch is still in-flight. When the GCD work completes and tries to deliver its result back to the event loop, it finds the loop already shut down, causing a crash. On fast machines the GCD work completes before shutdown, but on slow iOS simulators shutdown wins the race consistently. This crash also kills whichever other test happens to be running concurrently (typicallytestRepeatedTaskThatIsCancelledAfterRunningAtLeastTwiceNotifies).Modifications
EventLoopFuturefrom theflatMapBlockingchain and call.wait()on it before the function returns, ensuring the GCD dispatch delivers its result back to the event loop before shutdown begins. Move the assertions from the.whenSuccessclosure to after the.wait().Result