Fix lost-wakeup race on packageWaits in WaitForPackage - #3576
Merged
peterebden merged 1 commit intoAug 17, 2026
Conversation
Concurrent callers waiting on the same unparsed package could both pass the Get(key) == nil check and both Set a fresh channel; the second Set overwrote the first, and LogParseResult closes only the channel currently in the map, so the first waiter slept forever and the build wedged with "N tasks left, 0 workers busy". Use AddOrGet, as pendingPackages and pendingTargets already do.
jackmarsh
added a commit
to becomeliminal/rust-rules
that referenced
this pull request
Aug 16, 2026
Walks the workspace members and writes a BUILD file next to each: rust_library and rust_binary for the crate's products, rust_test for unit and integration tests, modules from the source tree, path dependencies mapped to member labels and registry dependencies to third_party aliases. Workspace-inherited edition and dependencies resolve through the root manifest. On a bare cargo repo it also scaffolds third_party/rust/BUILD, .plzconfig and plugins/BUILD, then chains the workspace's Cargo.lock into the existing lockfile import. Existing BUILD files are never overwritten; build scripts, optional features and renames are reported for follow-up. Proven end to end: a 40-crate cargo workspace imports, builds and tests green through the plugin. That repo also surfaced an upstream plz race (WaitForPackage lost-wakeup, wedged parse at scale) — root-caused, fix + regression test submitted as thought-machine/please#3576, noted in PARITY hardening. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
peterebden
approved these changes
Aug 17, 2026
Collaborator
There was a problem hiding this comment.
Ah yes, that sounds right; I think I found a similar thing in #3569 . Ended up changing Get completely, but this seems fine here.
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.
I've been building rust-rules, a Rust plugin for Please. While testing it on a repo with ~40 packages, each subincluding the plugin's build_defs, cold builds would intermittently hang at
N tasks left, 0 workers busy, parsing M BUILD files.The goroutine dump showed a single parser stuck in
subincludeTarget → WaitForPackage → waitOnChan. The cause is a race inWaitForPackage. Two parsers racing for the same unparsed package can both seepackageWaits.Get(key) == niland both callSet. The secondSetoverwrites the first thread's channel, andLogParseResultcloses only the channel currently in the map, so the first thread waits forever.The fix makes the insertion atomic with
AddOrGet, matchingpendingPackagesandpendingTargetsin the same file. One caller inserts the canonical channel and queues the parse; everyone else waits on that channel and is woken by the existing close.Added a regression test that races 32 callers against the package parse completing. It fails on master within a few iterations and passes with the fix, including under
-race.Reproduced on v17.27.0 and v17.31.2. Stock plz wedged 11 of 30 cold cycles on my machine; patched ran 30 clean.
plz test //src/core/...passes.