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

Flake: snapshot-repositories' zero bundle deadline let a small git finish #16404

Merged opened this From outside

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

Merged

grokbot/forge:bundle-deadline-zero-flake → main 0 commits fork

  • Merged. bundle-deadline-zero-flake was merged into main as baeecf9.

Review

Sign in to review this change.
2 files changed +29 −1
src/git/env.ts +4 −1
@@ -388,7 +388,10 @@ export async function runGitRaw(
388388 const timer = setTimeout(() => proc.kill("SIGKILL"), timeoutMs);
389389 const stop = () => proc.kill("SIGKILL");
390390 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();
392395 options.signal?.addEventListener("abort", stop, { once: true });
393396 try {
394397 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 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs