Skip to content

Fix testFlatBlockingMapOnto crashing on iOS simulator#3555

Merged
rnro merged 2 commits intoapple:mainfrom
rnro:testFlatBlockingMapOnto_failure
Mar 19, 2026
Merged

Fix testFlatBlockingMapOnto crashing on iOS simulator#3555
rnro merged 2 commits intoapple:mainfrom
rnro:testFlatBlockingMapOnto_failure

Conversation

@rnro
Copy link
Copy Markdown
Contributor

@rnro rnro commented Mar 19, 2026

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.

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.
@rnro rnro closed this Mar 19, 2026
@rnro rnro reopened this Mar 19, 2026
@rnro rnro added the semver/none No version bump required. label Mar 19, 2026
@rnro rnro force-pushed the testFlatBlockingMapOnto_failure branch from 0a21e27 to 433878d Compare March 19, 2026 13:24
@rnro rnro merged commit 5243468 into apple:main Mar 19, 2026
53 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

semver/none No version bump required.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants