Fix deadlock in cmdio tea program queueing#5505
Merged
Merged
Conversation
acquireTeaProgram blocked on teaDone while holding teaMu, but releaseTeaProgram needs teaMu to close that channel, so queueing a second tea.Program behind an active one deadlocked both goroutines. Wait with the lock released and re-check in a loop before registering. Co-authored-by: Isaac
Collaborator
|
Commit: 4d5c4c4
22 interesting tests: 15 SKIP, 7 KNOWN
Top 29 slowest tests (at least 2 minutes):
|
Co-authored-by: Isaac
pietern
approved these changes
Jun 10, 2026
pietern
left a comment
Contributor
There was a problem hiding this comment.
I want to get rid of this when we can and allocate a single tea.Program for the lifetime of the command instead of swapping in and out. Needs a close look.
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.
Why
Found during a full-repo review of the CLI.
acquireTeaPrograminlibs/cmdiois documented to queue a newtea.Programbehind an active one, but it waits on theteaDonechannel while holdingteaMu.releaseTeaProgramneeds that same mutex to close the channel, so the moment two programs overlap, both goroutines deadlock and the CLI hangs. It is latent today because callers happen to serialize, but any future concurrent spinner or prompt would trip it.Changes
Before, starting a second
tea.Programwhile one was active deadlocked; now the second one waits for the active program to finish and then runs.acquireTeaProgramcopiesteaDoneunder the lock, releases the lock while waiting on the channel, and re-checks in a loop before registering, since another acquirer may take the slot first.releaseTeaProgramandWaitare unchanged.Test plan
TestAcquireTeaProgramWaitsForReleaseinlibs/cmdio/io_test.go: starts a second acquire while a program is active, asserts it queues, then asserts it completes after release, with a timeout guarding against deadlockgo test -race ./libs/cmdio/...passes./task fmt-q,./task lint-q, and./task checkspassThis pull request and its description were written by Isaac.