Repository navigation
fix(stub): extract cache entries to a temp dir and rename into place - #78
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Cache cleanup still contains deletion races, incomplete-cache detection is insufficient, and failed extraction can leak temporary artifacts.
1 open finding
What changed in this PR
Updates launcher cache extraction to reduce concurrent first-run failures.
Changes:
- Extracts runtime, application, and CRaC data through temporary paths.
- Atomically publishes completed cache entries.
- Adds concurrent extraction regression tests.
| File | Description |
|---|---|
src/pack/stub.rs |
Implements temporary extraction, publication, cleanup, and concurrency tests. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
Going through the rest of the Copilot summary on 6c0938b: the leak on failed extraction was real, a broken |
Two copies of the same binary started on an empty cache could race: the second saw bin/ while lib/ was still being written and launched a broken runtime. Runtime, app.jar and CRaC checkpoint now extract into a private temp path and get renamed into the cache, so a reader only ever sees a complete entry. Signed-off-by: Avelino <31996+avelino@users.noreply.github.com>
bin/java existing doesn't prove the runtime is whole: a run killed mid-extraction, or an older stub that extracted in place, leaves bin/ with lib/ half written. Each entry now gets .jbundle-complete written in the temp dir after extraction succeeds, and markerless entries are moved aside and rebuilt once. Signed-off-by: Avelino <31996+avelino@users.noreply.github.com>
Under set -e a failed tar or gzip exited the stub with its temp dir or temp jar still in the cache. Clean it up before exiting. Signed-off-by: Avelino <31996+avelino@users.noreply.github.com>
587d571 to
a315965
Compare

What
The launcher stub extracted the runtime straight into
~/.jbundle/cache/rt-<hash>and checked forbin/to decide it was done. When two copies of the same binary start at once on an empty cache, the second one seesbin/whilelib/is still being written and runs a half-extractedjava. That's the flake we've been seeing in the e2e job.Now every cache entry (runtime, app.jar, CRaC checkpoint) is extracted into a private temp path next to its final spot and renamed into place:
mktemp -dthenmv. If another copy won the race, the loser's dir is cleaned up (including the case wheremvdrops it inside the existing one).mv -f, which is atomic.bin/javabeing executable, and a leftoverrt-<hash>withoutbin/from an older stub gets cleared before retrying.How it was tested
concurrent_first_runs_never_see_partial_extraction: packs a real binary with a fake runtime (abin/javascript that fails unless the lastlib/file and the full app.jar are there), starts 4 copies at once on an emptyHOME, 5 rounds, and checks nothing is left behind in the cache.main: fails 3 out of 3 runs.cargo test: 190 unit + 2 e2e passed (the e2e cases skip here, no JDK on this machine, so CI is the real check for them).cargo clippy --all-targets -- -D warningsandcargo fmt --checkclean.Not tested: a real macOS run by hand. The test runs on the macOS CI job, and
mktemp -d <template>is supported there.Real-world confirmation: on the same day, the e2e job on #62 (twice) and #79 (once) failed with
could not open .../.jbundle/cache/rt-<hash>/lib/jvm.cfg, which is exactly this race. This branch's own CI run passed on all three OSes.