fix(scheduler): reap subreaper children on an isolated loop on shutdown#15383
Open
rgrinberg wants to merge 1 commit into
Open
fix(scheduler): reap subreaper children on an isolated loop on shutdown#15383rgrinberg wants to merge 1 commit into
rgrinberg wants to merge 1 commit into
Conversation
On shutdown, [kill_and_wait_for_all_processes] reaps escaped subreaper children in a second [Fiber.run]. By then the main run has finished and cleared [current], yet that run reused the scheduler's event queue, so it resumed the finished run's fibers (a different fiber scheduler -> "advance ... in a different scheduler") and ran code with no current scheduler ([Option.value_exn] in [t ()]). Give the cleanup its own [Event.Queue] + [Async_io] loop so it only ever observes its own async-io completions. Signed-off-by: Rudi Grinberg <me@rgrinberg.com> Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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
Fix internal errors during scheduler shutdown when the subreaper child-process
cleanup runs.
On shutdown,
kill_and_wait_for_all_processesreaps any "escaped" subreaperchildren in a second
Fiber.run. By that point the main run has finished and itscurrentbinding has been cleared, yet that second run reused the scheduler'sown event queue. As a result it could:
giving
advance: it's illegal to call advance with a fiber created in a different scheduler, andcleanup_subreaper_child_processesand the file-watcher's
shutdown) with no current scheduler, givingOption.value_exnfromt ().This surfaced as a flaky failure in
test/blackbox-tests/test-cases/watching/shutdown.t:watch mode + an RPC server keeps fibers parked on
Async_iotimers/ivars, so onshutdown there are stale fills and in-flight fibers for the cleanup run to trip
over (a plain build has none).
Fix
Run the subreaper cleanup on a fresh, isolated
Event.Queue+Async_ioloop instead of the scheduler's shared queue, so it only ever observes its own
async-io completions — never the finished run's leftover fills or fibers. The
reap logic is unchanged; it is just parameterized over the async-io loop it uses.
The public
cleanup_subreaper_child_processes(used by the build loop within themain run) keeps using the scheduler's own loop and is unaffected.