Fix a crash from scheduler/worker disconnect [1.6-patch-2] - #2643
Open
cormacrelf wants to merge 2 commits into
Open
Fix a crash from scheduler/worker disconnect [1.6-patch-2]#2643cormacrelf wants to merge 2 commits into
cormacrelf wants to merge 2 commits into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
Description
Fixes a bug where a routine scheduler disconnect could panic the worker in some cases if an action happened to be in transit at the time. If you worker and scheduler run in the same instance, this kills the entire nativelink process.
The crash happens because the worker panics it cannot get its
actions_in_transitcounter to zero within a timeout, however the very act of disconnecting and cancelling the action-in-transit future prevented decrementing the counter and returning it to zero.This fixes it with RAII so that when the action's future is cancelled (dropped) the counter still gets decremented.
Full crash path
LocalWorkerImpl::runreturnsErrwhenever the scheduler connection drops — an ordinary, expected event that the worker is supposed to recover from by killing its running actions and reconnecting.Before it can do that,
LocalWorker::runwaits foractions_in_transitto drain to zero. If it doesn't drain withinACTIONS_IN_TRANSIT_TIMEOUT_S(10s), it bails out instead of reconnecting:This is fine, and the PR does not change this behaviour.
That
Erris the return value of the worker's root future, so it comes out oftry_join_all(root_futures)ininner_main, which panics on any root future error:inner_mainis awaited directly underruntime.block_onon the main thread, so this panic terminates the process — including the scheduler, the CAS, and every other worker in a colocated deployment.The reason the drain could never complete:
actions_in_transitwas incremented before spawning the action future, but decremented from inside it, oncecreate_and_add_actionresolved:The fix introduces
ActionsInTransitGuard, an RAII guard that increments the counter on construction and decrements it inDrop, so the count is correct whether the action future completes normally or is aborted mid-flight. The disconnect then drains immediately and the worker reconnects as intended.Type of change
How Has This Been Tested?
New regression test
disconnect_with_action_in_transit_reconnects_testinnativelink-worker/tests/local_worker_test.rs.Also adjusts the test harness's sleep stub to
yield_now()instead of a no-op, so loops that spin on the sleep function still give the runtime a chance to run Drop::drop on aborted futures, matching real scheduler behavior.Checklist
bazel test //...passes locallygit amendsee some docsThis change is