fix: deadlock between Task.Size and redrawProgress under parallel install#564
Merged
joshfriend merged 2 commits intocashapp:masterfrom Apr 21, 2026
Merged
Conversation
…tall cashapp#558 parallelised hermit install, which lets many goroutines drive per-package download progress concurrently. cache/http.go calls task.Size(total) followed by task.Add(n) for each chunk received; with a single active task the cycle below could never close, but with many it closes in two hops. Lock orderings: Task.Size: task.lock -> ui.lock (via UI.swapSize) UI.redrawProgress: ui.lock -> task_i.lock (via liveOperations / op.status) Goroutine A inside task_A.Size holds task_A.lock waiting on ui.lock. Goroutine B, having just returned from its own task.Add's critical section, enters redrawProgress holding ui.lock and iterates operations waiting on task_A.lock. Deadlock is silent because the UI itself is blocked, so no progress output is produced before the job is killed — matches the wild symptom of 'hermit install' stalling with zero output after v0.52.0. Fix: release task.lock in Task.Size before calling UI.swapSize. The oldSize → newSize delta is additive and commutative, so doing the swapSize outside the task's critical section loses nothing. Regression test fans out goroutines each interleaving Size/Add on their own task (mirroring cache/http.go) and fails the Go test binary explicitly with a goroutine dump rather than hanging for the default test timeout.
358b19b to
45fe13f
Compare
joshfriend
approved these changes
Apr 21, 2026
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
#558 parallelised
hermit install, which lets many goroutines drive per-package download progress concurrently.cache/http.gocallstask.Size(total)followed bytask.Add(n)for each chunk received; with a single active task the cycle below could never close, but with many it closes in two hops.Lock orderings:
Goroutine A inside
task_A.Sizeholdstask_A.lockwaiting onui.lock. Goroutine B, having just returned from its owntask.Add's critical section, entersredrawProgressholdingui.lockand iterates operations waiting ontask_A.lock. Deadlock is silent because the UI itself is blocked, so no progress output is produced before the job is killed — matches the wild symptom ofhermit installstalling with zero output afterv0.52.0on CI jobs that install many packages at once.Fix
Release
task.lockinTask.Sizebefore callingUI.swapSize. TheoldSize → newSizedelta passed toswapSizeis additive and commutative, so doing the swap outside the task's critical section loses nothing.Test
ui/task_test.go::TestConcurrentTaskSizeAndAddNoDeadlockfans out goroutines each interleavingSize/Addon their own task (mirroringcache/http.go's download loop).ui.lock↔task.lockcycle.Passes
go test -race ./ui/and existinggo test ./app/.