Repository navigation
fix(tarball): fix a lost-wakeup hang in the tarball mem cache - #13166
Conversation
…he slot A task that found the per-URL cache slot InProgress released the RwLock read guard and only then polled Notify::notified(). notify_waiters() stores no permit - it wakes only futures already registered at that instant - so an owner that flipped the slot to Available/Failed and notified inside that window left the waiter parked forever with nothing ever notifying the slot again. The window needs the owner to complete its flip on another worker thread while the waiter is preempted between the guard drop and its first poll, which is why it only surfaced as a rare hang on oversubscribed CI runners: pacquet-cli::add save_prefix_empty_writes_exact_version (a 0.2s test) hung for over an hour and wedged the Rust CI job at https://github.com/pnpm/pnpm/actions/runs/29705938247. The waiter path hits this window on every cold add/install of a single package: the resolve-time prefetcher spawns the owning fetch and the install pass then waits on the same slot. A detached prefetch task losing the same race also pinned the store-index writer channel open, hanging the final writer_task.await instead - same root cause, either direction. Fix per the documented tokio pattern: pin the Notified future and enable() it to register interest before re-checking the slot state, awaiting only if the slot is still InProgress, in a loop. A wakeup that lands between the re-check and the await now completes the already registered future instead of vanishing. The exact interleaving cannot be reproduced deterministically without loom (it requires preempting the waiter mid-poll), so no regression test accompanies the fix; the nextest terminate-after guardrail added alongside turns any recurrence into a visible 5-minute test failure.
nextest's default slow-timeout only marks a test SLOW every 60s and waits forever, so a single hung test binary wedged the whole job until someone cancelled it from outside, with no output from the offender. Set terminate-after = 5 in a workspace .config/nextest.toml: a test stuck past 300s is now killed and reported as TIMEOUT with its captured output, and the rest of the run completes. The threshold keeps 3.5x headroom over the suite's slowest legitimate tests (the fetch-timeout retry-ladder tests, ~70s on Linux/Windows and ~85s on macOS). Also cap the test job at 60 minutes as a backstop for hangs outside nextest (stuck cargo build or tool download): warm-cache runs finish in about 5 minutes, cold-cache workspace rebuilds get the rest of the hour, and the GitHub default is 360 minutes.
The perfectionist::impure_macro_arguments dylint requires impure expressions to be bound outside the macro call.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughThe tarball memory-cache waiter now prevents missed wakeups by registering notifications before state checks and retrying while downloads remain in progress. Nextest and CI receive timeout safeguards, and a patch changeset documents the fix. ChangesTarball cache reliability
Estimated code review effort: 3 (Moderate) | ~20 minutes Suggested labels: Suggested reviewers: ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
PR Summary by QodoFix tarball mem-cache lost wakeup and add Rust CI timeout guardrails
AI Description
Diagram
High-Level Assessment
Files changed (4)
|
Confidence Score: 5/5Safe to merge — the fix correctly resolves a rare but real hang with no observable behavior change for the normal fast path. The waiter loop follows the tokio-documented notify_waiters pattern precisely: enable() is called before the state check, the read guard is released before the await, and the defensive InProgress loop iteration is harmless. The owner branch is unchanged. CI guardrails are correctly sized and add no functional risk. No files require special attention. Reviews (1): Last reviewed commit: "style(tarball): let-bind the Notified fu..." | Re-trigger Greptile |
Micro-Benchmark ResultsLinux |
Code Review by Qodo
1. Lost fail-fast invariant check
|
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #13166 +/- ##
=======================================
Coverage 86.44% 86.44%
=======================================
Files 508 508
Lines 85078 85086 +8
=======================================
+ Hits 73542 73554 +12
+ Misses 11536 11532 -4 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
`node --test pnpm/scripts/*.test.mjs` now fails when a nextest profile declares `slow-timeout` without `terminate-after`. Without it, nextest only marks a test SLOW every `period` and then waits for it forever, so a single hung test binary wedges the run until the CI job is killed from outside — the 80-minute `Rust CI / Test` job recorded in pnpm/tasks#32. The backstop is already in place: `.config/nextest.toml` has carried `slow-timeout = { period = "60s", terminate-after = 5 }` since pnpm#13166, and profiles that declare no `slow-timeout` inherit it from `default`. Nothing asserted that, so an edit could drop `terminate-after` and bring the wedge back in silence. This pins the existing backstop rather than adding a second deadline: the bounds the task asked for are already there, in pnpr's per-request upstream timeout and in pacquet's fetch-timeout. Refs pnpm/tasks#32
* test(ci): pin the nextest terminate-after backstop `node --test pnpm/scripts/*.test.mjs` now fails when a nextest profile declares `slow-timeout` without `terminate-after`. Without it, nextest only marks a test SLOW every `period` and then waits for it forever, so a single hung test binary wedges the run until the CI job is killed from outside — the 80-minute `Rust CI / Test` job recorded in pnpm/tasks#32. The backstop is already in place: `.config/nextest.toml` has carried `slow-timeout = { period = "60s", terminate-after = 5 }` since #13166, and profiles that declare no `slow-timeout` inherit it from `default`. Nothing asserted that, so an edit could drop `terminate-after` and bring the wedge back in silence. This pins the existing backstop rather than adding a second deadline: the bounds the task asked for are already there, in pnpr's per-request upstream timeout and in pacquet's fetch-timeout. Refs pnpm/tasks#32 * test(ci): cover per-test slow-timeout overrides in the backstop guard `[[profile.*.overrides]]` sections land inside the body of the profile they belong to, and the guard only looked at the first `slow-timeout` declaration there, so an override that named a period without `terminate-after` slipped through. That case is real: nextest resolves `slow-timeout` as one setting (`nextest-runner/src/config/overrides/imp.rs`, `TestSettings::slow_timeout`), and `SlowTimeout::terminate_after` is an `Option`, so an override that sets only `period` replaces the profile's policy and a test it matches can be marked SLOW and then waited for forever. Scan every `[[profile.*.overrides]]` section as well, while still skipping profiles and overrides that declare no `slow-timeout`. Verified against the real config and with both negative controls: an override declaring `slow-timeout = "10s"` fails the guard naming `[profile.probe.overrides]`, while `slow-timeout = { period = "10s", terminate-after = 3 }` passes it. Refs pnpm/tasks#32.
Summary
The Rust CI job for the 11.15.1 release commit hung for 62 minutes until it was cancelled: https://github.com/pnpm/pnpm/actions/runs/29705938247/job/88242852400. The last test of the run,
pacquet-cli::add save_prefix_empty_writes_exact_version(normally 0.2s), never finished — the spawned pacquet process was still alive when the job died.Root cause: a lost wakeup in
DownloadTarballToStore::run_with_mem_cache. A task that finds the per-URL cache slotInProgressreleased theRwLockread guard and only then polledNotify::notified().notify_waiters()stores no permit — it wakes only futures registered at that instant — so if the owning fetch flips the slot toAvailable/Failedand notifies inside that window, the waiter parks forever (nothing ever notifies the slot again). The window requires the owner to complete its flip on another worker thread while the waiter is preempted mid-poll, which is why it surfaced only once, on an oversubscribed CI runner. The waiter path is exercised on every coldadd/install: the resolve-time prefetcher owns the fetch and the install pass waits on the same slot (or vice versa — a parked detached prefetch task pins the store-index writer channel and hangs the finalwriter_task.awaitinstead).The fix follows the documented tokio pattern: pin the
Notifiedfuture andenable()it to register interest before re-checking the slot, awaiting only if the slot is stillInProgress, in a loop.Two CI guardrails ride along so any similar hang can never wedge a job again:
.config/nextest.tomlwithslow-timeout = { period = "60s", terminate-after = 5 }: a test stuck past 300s is killed and reported as TIMEOUT with its captured output, and the rest of the run completes. 300s keeps ~3.5× headroom over the suite's slowest legitimate tests (the fetch-timeout retry-ladder tests: ~70s on Linux/Windows, ~85s on macOS).timeout-minutes: 60on the Rust CI test job as a backstop for hangs outside nextest (warm-cache runs finish in ~5 minutes; cold-cache rebuilds get the rest of the hour).Rust-only: the TypeScript CLI dedupes concurrent tarball fetches through shared promises, which cannot lose a completion, so there is nothing to port.
Squash Commit Body
Checklist
pnpm/port, or the description notes what still needs porting.pnpm changeset) if this PR changes any publishedpackage. Keep it short and written for pnpm users — it becomes a release note.
mid-poll between two specific instructions, which cannot be scheduled
deterministically without loom; the existing waiter-path tests cover the new
loop, and the nextest terminate-after guardrail turns any recurrence into a
5-minute TIMEOUT failure with output.
Written by an agent (Claude Code, claude-fable-5).
Need help on this PR? Tag
/codesmithwith what you need. Autofix is disabled.Summary by CodeRabbit
Bug Fixes
Tests