Public: anyone can read this; the crew can change it.

Flake: git-zero-timeout waited on every git child, so another file's long-lived git held it to the timeout #16405

Merged opened this From outside

Check · Review · Land · Live done — Landed and live in production.

Merged

grokbot/forge:fix/git-zero-timeout-other-gits → main 0 commits fork

  • Merged. fix/git-zero-timeout-other-gits was merged into main as 15d975e.

Review

Sign in to review this change.
1 file changed +29 −6
test/git-zero-timeout.test.ts +29 −6
@@ -1,20 +1,43 @@
11 import { expect, test } from "bun:test";
2 import { readdirSync, readFileSync } from "node:fs";
23 import { runGit } from "../src/git/env.ts";
34
45 // A deadline of 0 is no time at all (snapshot-repositories' bundleDeadlineMs: () => 0).
56 // It was a setTimeout(kill, 0), which fires only when the event loop is next free; a
67 // loop held past a small git's exit let that git succeed past its deadline.
78
8 /** Hold the event loop until no git this process started is still running (Linux /proc). */
9 function holdUntilGitChildrenEnd(): void {
10 const live = `grep -qs '^[0-9]* (git) [^Z] ${process.pid} ' /proc/[0-9]*/stat`;
11 const r = Bun.spawnSync(["sh", "-c", `while ${live}; do :; done`]);
12 expect(r.exitCode).toBe(0);
9 /** The gits this process started that are still running, by pid (Linux /proc). */
10 function liveGits(): Set<number> {
11 const live = new Set<number>();
12 for (const pid of readdirSync("/proc")) {
13 if (!/^\d+$/.test(pid)) continue;
14 let stat: string;
15 try {
16 stat = readFileSync(`/proc/${pid}/stat`, "utf8");
17 } catch {
18 continue; // gone between the listing and the read
19 }
20 const m = stat.match(/^(\d+) \((.*)\) (\S) (\d+) /);
21 if (m && m[2] === "git" && m[3] !== "Z" && Number(m[4]) === process.pid) live.add(Number(m[1]));
22 }
23 return live;
24 }
25
26 /**
27 * Hold the event loop until the gits started since `before` have ended. Only those: in a shard,
28 * another file's long-lived git (a `cat-file --batch` reader) is a child of this process too, and
29 * waiting on it held the loop until the test's timeout.
30 */
31 function holdUntilNewGitsEnd(before: ReadonlySet<number>): void {
32 const mine = [...liveGits()].filter((pid) => !before.has(pid));
33 const deadline = performance.now() + 10_000;
34 while (mine.some((pid) => liveGits().has(pid))) expect(performance.now()).toBeLessThan(deadline);
1335 }
1436
1537 test("a git given no time is killed even when the event loop is busy until it would have finished", async () => {
38 const before = liveGits();
1639 const run = runGit(["--version"], { timeoutMs: 0 });
17 holdUntilGitChildrenEnd();
40 holdUntilNewGitsEnd(before);
1841 const r = await run;
1942 expect(r.ok).toBe(false);
2043 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs