Repository navigation
restart: fix DelayStart store-lock deadlock - #3315
Open
SabyaXSachi wants to merge 1 commit into
Open
SabyaXSachi wants to merge 1 commit into
SabyaXSachi wants to merge 1 commit into
Conversation
DelayStart cancelled an existing delayed start for the same task ID and waited for its goroutine on doneCh while the caller held the store's write lock. A superseded goroutine that had already passed its timers sits blocked in MemoryStore.Update waiting for that same lock, so the wait never finished: the updater's Batch deadlocked and every subsequent store write queued behind the lock until process restart. Reported in moby/moby#54128. Cancel the superseded delay and register the replacement atomically under r.mu instead of waiting. That a superseded goroutine cannot perform a stale StartNow rests on the requirement, now documented, that every DelayStart caller holds the store write lock: a replacement therefore cannot run concurrently with a superseded goroutine's store transaction, and the goroutine observes its cancellation in the transaction callback and skips StartNow. The deferred map cleanup is identity-guarded so a superseded goroutine cannot delete a newer delay's entry, and doneCh is still closed exactly once by the owning goroutine. Adds restart_test.go covering: replacement while the write lock is held (deadlocks before this change), stale-StartNow prevention, identity-guarded cleanup, rapid repeated replacements, and the non-superseded start path. Fixes moby/moby#54128 Signed-off-by: SabyaXSachi <sabyasachipanda507@gmail.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.
What I did
Fixed a deadlock in
Supervisor.DelayStartthat could block the Swarm manager's store write lock indefinitely.When a delayed start was replaced while the caller held the store write lock, the existing implementation cancelled the previous delay and synchronously waited for its goroutine to finish. If that goroutine had already passed its timers and was waiting to acquire the same store lock through
MemoryStore.Update, neither goroutine could proceed.Fixes moby/moby#54128.
How I did it
r.mu.StartNow.doneChexactly once.DelayStartwhile holding the store write lock.How to test it
Added
manager/orchestrator/restart/restart_test.gocovering:StartNowexecution after cancellation.Validation performed:
go test -race ./manager/orchestrator/...passed.TestTimestampsfailure was not introduced by this change.git diff --checkpassed.Description for the changelog
Fix a deadlock in delayed task restart handling when replacing an existing delayed start while holding the store write lock.
AI assistance disclosure
AI tools assisted with investigation and implementation of this contribution. I reviewed the relevant source code, examined the concurrency behavior, reviewed the implementation and tests, and take responsibility for the submitted changes and their maintenance.