Repository navigation
jobserver: replace the pool when a compiler dies holding tokens - #3047
Conversation
The server shares its private jobserver with the rustc processes it starts. When a client disconnects, the server kills that rustc (kill_on_drop), and any tokens it had read from the pipe never come back. On a long-lived server the pool shrinks until nothing can start (mozilla#2874). When a child that was given the shared jobserver does not exit on its own, move new work to a fresh, full pool. Children still running on the old pool return their tokens to it, and it is dropped once the last of them finishes. A semaphore shared across pools keeps the number of concurrent children at the configured limit. Build-owned fifo: jobservers are unchanged. Fixes mozilla#2874 Assisted-by: OpenCode (openai/gpt-6.1-terra)
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3047 +/- ##
==========================================
+ Coverage 78.92% 80.03% +1.10%
==========================================
Files 75 76 +1
Lines 46005 47504 +1499
==========================================
+ Hits 36310 38019 +1709
+ Misses 9695 9485 -210 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
| let token = self.jobserver.acquire().await?; | ||
| let mut inner = tokio::process::Command::from(inner); | ||
| let child = inner | ||
| .kill_on_drop(true) |
There was a problem hiding this comment.
if the spawn fails here, token is dropped with shared set and not exited, so we retire a pool that lost nothing, no?
could you please mark it as exited (or only set shared) once the spawn succeeded?
There was a problem hiding this comment.
Good catch — fixed in 90f1c13. Acquired::configure no longer sets shared; mark_shared() is only called after spawn() succeeds, with a failed_spawn_does_not_retire_jobserver_pool test.
| r#"a=${CARGO_MAKEFLAGS##*--jobserver-auth=}; [ "$(head -c1 /proc/self/fd/${a%,*} | wc -c)" -eq 1 ] && kill -9 $$"#, | ||
| ]); | ||
| victim.share_jobserver(); | ||
| let timeout = std::time::Duration::from_secs(10); |
There was a problem hiding this comment.
same shell snippet as in the previous test, could be a const, no?
There was a problem hiding this comment.
Done in 90f1c13 — extracted to const LEAK_TOKEN_AND_SIGKILL.
| fifo.configure(cmd); | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
exited as both a field and a method that only sets it on_its_own is a bit confusing, maybe exited_on_its_own?
There was a problem hiding this comment.
Fixed in 90f1c13: renamed the field to exited_on_its_own and the method to record_exit so they do not share a name.
- Mark an acquired token as shared only after spawn() succeeds, so a spawn failure does not retire a healthy pool; add a regression test. - Rename Acquired::exited to exited_on_its_own (field) and record_exit (method) to clarify its meaning and avoid reusing the same name for both. - Deduplicate the Linux token-leak shell snippet in mock_command tests into a shared constant.
|
Thanks for your PR |
Fixes #2874.
The server shares its private jobserver with the rustc processes it starts. When a client disconnects, the server kills that rustc (
kill_on_drop), and any tokens it had read from the pipe never come back. On a long-lived server the pool shrinks until nothing can start. I hit this on 0.19.0 with one daemon shared by many builds: the pool went from 32 to 0 and every compile hung until I restarted it.With this change, when a child that was given the shared jobserver doesn't exit on its own (it dies from a signal, or its wait is dropped), the server moves new work to a fresh, full pool. Children still running on the old pool give their tokens back to it, and it's dropped once the last of them finishes. A semaphore shared across pools keeps the number of concurrent children at the configured limit, so a replacement never lets more children run than before. Tokens a rustc borrows from an older pool aren't counted against the new one, so the borrowed total can briefly go over the limit until those children finish; the child count can't. Build-owned
fifo:jobservers (#2978) are unchanged.The only dependency change is tokio's
syncfeature, for thewatchchannel and the semaphore.Tests:
killed_child_does_not_leak_jobserver_tokens: a child takes a token and kills itself with SIGKILL; both tokens must be available again. It times out on main and passes with this change.replaced_pool_keeps_the_child_limit: with a child still running on the old pool, a replacement must not hand out more slots than the limit.Both are Linux-only because they read the jobserver fd through
/proc, which also keeps them working under dash.cargo clippywith the CI flags andcargo test --locked --lib --bins --testspass locally. I couldn't run the CUDA/HIP tests here.I used AI assistance (OpenCode with GPT-6.1 Terra, reviewed with GPT-6.2 Sol and Claude) to write this change. I've read the diff and will answer review questions myself.
Reviewed with sol-loop: 3 rounds with openai/gpt-6.2-sol (xhigh). The last round's only open finding, a line over 100 columns, was fixed afterwards by running rustfmt through treefmt, so there was no final approve verdict.