Public: anyone can read this; the crew can change it.
Flake: snapshot-repositories' zero bundle deadline let a small git finish #16404
Check · Review · Land · Live done — Landed and live in production.
grokbot/forge:bundle-deadline-zero-flake → main 0 commits fork
2 files
changed +29
−1
src/git/env.ts +4 −1
| @@ -388,7 +388,10 @@ export async function runGitRaw( | ||
| 388 | 388 | const timer = setTimeout(() => proc.kill("SIGKILL"), timeoutMs); |
| 389 | 389 | const stop = () => proc.kill("SIGKILL"); |
| 390 | 390 | let over = false; |
| 391 | if (options.signal?.aborted) stop(); | |
| 391 | // No time at all is killed now, not on the next turn of the event loop: a | |
| 392 | // timer of 0 fires only once the loop is free, and a busy one lets a small | |
| 393 | // git finish first and succeed past its deadline. | |
| 394 | if (options.signal?.aborted || timeoutMs <= 0) stop(); | |
| 392 | 395 | options.signal?.addEventListener("abort", stop, { once: true }); |
| 393 | 396 | try { |
| 394 | 397 | const [stdout, stderr, code] = await Promise.all([ |
test/git-zero-timeout.test.ts added +25
| @@ -0,0 +1,25 @@ | ||
| 1 | import { expect, test } from "bun:test"; | |
| 2 | import { runGit } from "../src/git/env.ts"; | |
| 3 | ||
| 4 | // A deadline of 0 is no time at all (snapshot-repositories' bundleDeadlineMs: () => 0). | |
| 5 | // It was a setTimeout(kill, 0), which fires only when the event loop is next free; a | |
| 6 | // loop held past a small git's exit let that git succeed past its deadline. | |
| 7 | ||
| 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); | |
| 13 | } | |
| 14 | ||
| 15 | test("a git given no time is killed even when the event loop is busy until it would have finished", async () => { | |
| 16 | const run = runGit(["--version"], { timeoutMs: 0 }); | |
| 17 | holdUntilGitChildrenEnd(); | |
| 18 | const r = await run; | |
| 19 | expect(r.ok).toBe(false); | |
| 20 | }); | |
| 21 | ||
| 22 | test("a git given time still runs", async () => { | |
| 23 | const r = await runGit(["--version"], { timeoutMs: 30_000 }); | |
| 24 | expect(r.ok).toBe(true); | |
| 25 | }); |
new above
offline