Skip to content

Commit 429c0ac

Browse files
fix(server): timed-out git commands that ignore SIGTERM no longer stall other git work (#26601)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent a68bd77 commit 429c0ac

3 files changed

Lines changed: 41 additions & 7 deletions

File tree

‎apps/server/src/vcs/GitVcsDriver.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ export interface ExecuteGitInput {
5454
readonly env?: NodeJS.ProcessEnv;
5555
readonly allowNonZeroExit?: boolean;
5656
readonly timeoutMs?: number | null;
57-
readonly forceKillAfterMs?: number;
5857
readonly maxOutputBytes?: number;
5958
readonly appendTruncationMarker?: boolean;
6059
/** With appendTruncationMarker, line callbacks continue beyond the buffer cap for progress-only consumers. */

‎apps/server/src/vcs/GitVcsDriverCore.test.ts‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1804,6 +1804,45 @@ describe("rejected git refs", () => {
18041804
});
18051805

18061806
it.layer(layerTest)("GitVcsDriver core integration", (it) => {
1807+
// regression: #26577 a timed-out git that outlives its timeout holds a process permit
1808+
it.effect.skipIf(HostProcess.Platform.defaultValue() === "win32")(
1809+
"kills a timed-out git command that ignores SIGTERM",
1810+
() =>
1811+
Effect.gen(function* () {
1812+
const cwd = yield* makeTmpDir();
1813+
yield* initRepoWithCommit(cwd);
1814+
const pathService = yield* Path.Path;
1815+
const fileSystem = yield* FileSystem.FileSystem;
1816+
const markerPath = pathService.join(yield* makeTmpDir(), "outlived-timeout");
1817+
const driver = yield* GitVcsDriver.GitVcsDriver;
1818+
const trapped = yield* Deferred.make<void>();
1819+
1820+
const command = yield* driver
1821+
.execute({
1822+
operation: "GitVcsDriver.test.ignoresSigterm",
1823+
cwd,
1824+
args: [
1825+
"-c",
1826+
`alias.hang=!trap '' TERM; echo trapped; sleep 3; touch '${markerPath}'`,
1827+
"hang",
1828+
],
1829+
progress: {
1830+
onStdoutLine: (line) =>
1831+
line === "trapped" ? Deferred.succeed(trapped, undefined) : Effect.void,
1832+
},
1833+
})
1834+
.pipe(Effect.forkChild);
1835+
yield* Deferred.await(trapped);
1836+
// The driver's timeout ends a command the same way: by interrupting it.
1837+
yield* Fiber.interrupt(command);
1838+
1839+
assert.isFalse(
1840+
yield* fileSystem.exists(markerPath),
1841+
"the timed-out git command kept running until it finished on its own",
1842+
);
1843+
}),
1844+
);
1845+
18071846
it.effect("keeps large change sets available for status and commit preparation", () =>
18081847
Effect.gen(function* () {
18091848
const cwd = yield* makeTmpDir();

‎apps/server/src/vcs/GitVcsDriverCore.ts‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,6 @@ interface GitRefsSnapshot {
189189
interface ExecuteGitOptions {
190190
stdin?: string | undefined;
191191
timeoutMs?: number | null | undefined;
192-
forceKillAfterMs?: number | undefined;
193192
allowNonZeroExit?: boolean | undefined;
194193
fallbackErrorDetail?: string | undefined;
195194
env?: NodeJS.ProcessEnv | undefined;
@@ -995,7 +994,8 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
995994
ChildProcess.make(executable, commandInput.args, {
996995
cwd: commandInput.cwd,
997996
env: spawnEnv,
998-
forceKillAfter: input.forceKillAfterMs,
997+
// SIGTERM first lets git remove its lock files; SIGKILL ends one that ignores it.
998+
forceKillAfter: "1 second",
999999
...(runsGitWithoutConsole(hostPlatform, executable, commandInput.args)
10001000
? { detached: true, windowsHide: true }
10011001
: {}),
@@ -1164,9 +1164,6 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
11641164
...(options.env !== undefined ? { env: options.env } : {}),
11651165
allowNonZeroExit: true,
11661166
...(options.timeoutMs !== undefined ? { timeoutMs: options.timeoutMs } : {}),
1167-
...(options.forceKillAfterMs !== undefined
1168-
? { forceKillAfterMs: options.forceKillAfterMs }
1169-
: {}),
11701167
...(options.maxOutputBytes !== undefined ? { maxOutputBytes: options.maxOutputBytes } : {}),
11711168
...(options.appendTruncationMarker !== undefined
11721169
? { appendTruncationMarker: options.appendTruncationMarker }
@@ -1381,7 +1378,6 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
13811378
env: STATUS_UPSTREAM_REFRESH_ENV,
13821379
fallbackErrorDetail: "Background Git fetch exited with a non-zero status.",
13831380
timeoutMs: Duration.toMillis(STATUS_UPSTREAM_FETCH_TIMEOUT),
1384-
forceKillAfterMs: 1_000,
13851381
}).pipe(
13861382
Effect.asVoid,
13871383
Effect.tap(() =>

0 commit comments

Comments
 (0)