-
Notifications
You must be signed in to change notification settings - Fork 5k
install: never delete a concurrently published cache entry on Windows #33884
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Jarred-Sumner
wants to merge
5
commits into
main
Choose a base branch
from
claude/install-cache-publish-loser-race
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+176
−41
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a6b5e63
install: never delete a concurrently published cache entry on Windows
Jarred-Sumner 3b5cf84
install(windows): keep stale-cache eviction, add concurrent publish r…
robobun 7310b81
[autofix.ci] apply automated fixes
autofix-ci[bot] 8353d5b
install(windows): evict stale cache entry by handle, mirror package_m…
robobun 45ed0f6
test(28062): skip verdaccio fork on non-Windows, raise beforeAll timeout
robobun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| // https://github.com/oven-sh/bun/issues/28062 | ||
| // Windows: two `bun install` processes sharing BUN_INSTALL_CACHE_DIR race to | ||
| // publish the same cache entry. The loser must accept the winner's entry and | ||
| // never delete it; otherwise the winner's install fails with ENOENT opening | ||
| // the cache dir it just published. | ||
| import { afterAll, beforeAll, expect, test } from "bun:test"; | ||
| import { mkdir, rm, writeFile } from "fs/promises"; | ||
| import { bunEnv, bunExe, isWindows, tempDir, VerdaccioRegistry } from "harness"; | ||
| import { join } from "path"; | ||
|
|
||
| let verdaccio: VerdaccioRegistry | undefined; | ||
|
|
||
| beforeAll(async () => { | ||
| if (!isWindows) return; | ||
| verdaccio = new VerdaccioRegistry(); | ||
| await verdaccio.start(); | ||
| }, 60_000); | ||
|
|
||
| afterAll(() => { | ||
| verdaccio?.stop(); | ||
| }); | ||
|
robobun marked this conversation as resolved.
|
||
|
|
||
| // The destructive rename-out-and-delete lived in the #[cfg(windows)] publish | ||
| // path; POSIX uses an atomic RENAME_EXCHANGE and never had the ENOENT window. | ||
| test.skipIf(!isWindows)( | ||
| "concurrent installs sharing a cache dir do not delete each other's cache entries", | ||
| async () => { | ||
| const dependencies = { | ||
| "no-deps": "1.0.0", | ||
| "a-dep": "1.0.1", | ||
| "basic-1": "1.0.0", | ||
| "what-bin": "1.0.0", | ||
| "one-dep": "1.0.0", | ||
| "two-range-deps": "1.0.0", | ||
| "dep-with-tags": "1.0.0", | ||
| "dep-loop-entry": "1.0.0", | ||
| }; | ||
| const pkg = JSON.stringify({ name: "cache-race", private: true, dependencies }); | ||
|
|
||
| using root = tempDir("bun-install-cache-race", {}); | ||
| const cache = join(String(root), "shared-cache"); | ||
| const bunfig = `[install]\nregistry = "${verdaccio!.registryUrl()}"\n`; | ||
|
|
||
| const projects: string[] = []; | ||
| for (let i = 0; i < 4; i++) { | ||
| const dir = join(String(root), `p${i}`); | ||
| await mkdir(dir, { recursive: true }); | ||
| await writeFile(join(dir, "package.json"), pkg); | ||
| await writeFile(join(dir, "bunfig.toml"), bunfig); | ||
| projects.push(dir); | ||
| } | ||
|
|
||
| const env = { | ||
| ...bunEnv, | ||
| BUN_INSTALL_CACHE_DIR: cache, | ||
| }; | ||
|
|
||
| const install = async (cwd: string) => { | ||
| await using proc = Bun.spawn({ | ||
| cmd: [bunExe(), "install", "--ignore-scripts"], | ||
| cwd, | ||
| env, | ||
| stdout: "pipe", | ||
| stderr: "pipe", | ||
| stdin: "ignore", | ||
| }); | ||
| const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]); | ||
| return { cwd, stdout, stderr, exitCode }; | ||
| }; | ||
|
|
||
| // Before the fix, the loser's rename-out + delete of the winner's cache | ||
| // entry created a guaranteed ENOENT window (>=10ms of backoff) every time | ||
| // two processes collided on the same package, so a handful of rounds with | ||
| // a fresh cache is enough to hit it reliably. | ||
| for (let round = 0; round < 8; round++) { | ||
| await rm(cache, { recursive: true, force: true }); | ||
| for (const dir of projects) { | ||
| await rm(join(dir, "node_modules"), { recursive: true, force: true }); | ||
| await rm(join(dir, "bun.lock"), { force: true }); | ||
| } | ||
|
|
||
| const results = await Promise.all(projects.map(install)); | ||
| const failed = results.filter(r => r.exitCode !== 0); | ||
| if (failed.length) { | ||
| const detail = failed.map(r => `cwd=${r.cwd}\nstderr:\n${r.stderr}\nstdout:\n${r.stdout}`).join("\n---\n"); | ||
| expect(detail).toBe(""); | ||
| } | ||
| for (const r of results) { | ||
| expect(r.stderr).not.toContain("ENOENT"); | ||
| expect(r.exitCode).toBe(0); | ||
| } | ||
| } | ||
| }, | ||
| 120_000, | ||
| ); | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.