Repository navigation
Worker: build the cleanup mark's guard after the lock is released - #2843
Merged
amankrx merged 2 commits intoSep 30, 2026
Merged
Conversation
… a second mark cannot deadlock the runtime on its own mutex
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
corcillo
reviewed
Sep 30, 2026
corcillo
reviewed
Sep 30, 2026
amankrx
force-pushed
the
fix/cleanup-mark-self-deadlock
branch
from
September 30, 2026 16:32
c84fd62 to
20cfe39
Compare
…ide, and the sweep and a retry's stale removal hold it
amankrx
force-pushed
the
fix/cleanup-mark-self-deadlock
branch
from
September 30, 2026 16:33
20cfe39 to
cb19918
Compare
corcillo
approved these changes
Sep 30, 2026
corcillo
approved these changes
Sep 30, 2026
This branch was successfully deployed
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.
What and why
Three of four workers on the drydock bed stopped executing in the middle of a TensorFlow run while looking healthy: keepalives and readiness fine, the scheduler listing each at twelve of twelve, no timer-driven warning from any action. A native backtrace showed twelve of the eighteen runtime threads blocked in
parking_lot::RawMutex::lock_slow, one of them insideperform_cleanupthroughCleanupGuard::drop, called from the orphan sweep.perform_cleanuptook thecleaning_up_operationslock and built its guard withthen_some, which constructs the argument whatever the boolean says, so when the operation was already marked the guard was dropped at once and itsDroptook the same non-reentrant lock on the same thread. That thread never returns, and every thread that then comes to clean up or start an action queues behind it, while the keepalive task keeps the worker alive and unevictable. The orphan sweep marks every directory it visits everyorphan_sweep_interval_s, and a directory whose action is mid-cleanup is already marked, so the double mark is routine; every freeze sat on the sweep's cadence from the worker's start. The guard is now built only after the lock is released. The mark's other two holders are the orphan sweep and a retry removing its earlier attempt's stale directory, both brief, so an action's own cleanup now waits for the mark instead of stepping aside: stepping aside while the sweep held it skipped that cleanup for good and left the action's entries and reservations behind. The sweep checks ownership before taking the mark and again under it, giving it back at once for a directory that became owned in between, and the retry path takes the mark for its removal so it cannot race the sweep on the same tree.How was this verified?
running_actions_manager_test: with a mark held, a second mark and the sweep run on their own thread; the test waits ten seconds and fails instead of hanging. On the old code it deadlocks; on the new one the second mark is refused, the sweep leaves the directory to its cleanup, and removes it once the mark is released. Two more: an action's cleanup started while the mark is held does nothing until the mark is released and then removes the directory and its entry, and a retry started while the mark is held leaves the stale tree untouched until the release and then replaces it. On the bed four rebuilt workers ran through every sweep tick of two TensorFlow runs, and a planted two-hour-old directory on a live worker was removed on the next tick.Risk
An action whose cleanup used to be skipped under a held mark now waits for it, for as long as a sweep entry or a stale removal takes.
perform_cleanup,take_cleanup_markandCleanupGuardbecome public for the tests.AI assistance
An agent drafted the change and I reviewed every line.
This change is