Skip to content

Commit 6904b56

Browse files
committed
fix(server): let a branch checkout finish instead of killing it after 10 seconds
switchRef ran git checkout with a 10 second timeout. In a partial clone the checkout removes the old files and then downloads the target's blobs, so a slow download got killed after the work tree was emptied but before HEAD moved, leaving files missing on disk. Fixes #30368
1 parent 8ab024f commit 6904b56

2 files changed

Lines changed: 36 additions & 1 deletion

File tree

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4318,6 +4318,39 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
43184318
}),
43194319
);
43204320

4321+
it.effect("lets a slow checkout finish instead of killing it partway", () =>
4322+
Effect.gen(function* () {
4323+
const cwd = yield* makeTmpDir();
4324+
yield* initRepoWithCommit(cwd);
4325+
yield* git(cwd, ["branch", "slow-target"]);
4326+
const delegate = yield* ChildProcessSpawner.ChildProcessSpawner;
4327+
const checkoutStarted = yield* Deferred.make<void>();
4328+
const releaseCheckout = yield* Deferred.make<void>();
4329+
const spawner = ChildProcessSpawner.make((command) =>
4330+
Effect.gen(function* () {
4331+
if (ChildProcess.isStandardCommand(command) && command.args.includes("checkout")) {
4332+
yield* Deferred.succeed(checkoutStarted, undefined);
4333+
yield* Deferred.await(releaseCheckout);
4334+
}
4335+
return yield* delegate.spawn(command);
4336+
}),
4337+
);
4338+
const driver = yield* makeGitVcsDriverCore().pipe(
4339+
Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),
4340+
);
4341+
4342+
const switching = yield* driver
4343+
.switchRef({ cwd, refName: "slow-target" })
4344+
.pipe(Effect.forkChild);
4345+
yield* Deferred.await(checkoutStarted);
4346+
yield* TestClock.adjust("2 minutes");
4347+
yield* Deferred.succeed(releaseCheckout, undefined);
4348+
4349+
assert.deepEqual(yield* Fiber.join(switching), { refName: "slow-target" });
4350+
assert.equal(yield* git(cwd, ["branch", "--show-current"]), "slow-target");
4351+
}),
4352+
);
4353+
43214354
it.effect("rejects a missing branch without restoring a matching dirty file", () =>
43224355
Effect.gen(function* () {
43234356
const cwd = yield* makeTmpDir();

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4939,7 +4939,9 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
49394939
input.cwd,
49404940
[...checkoutArgs, "--"],
49414941
{
4942-
timeoutMs: 10_000,
4942+
// Killing a checkout partway leaves the work tree half written while HEAD stays put, and a
4943+
// partial clone can spend a long time downloading the target's blobs.
4944+
timeoutMs: null,
49434945
fallbackErrorDetail: "git checkout failed",
49444946
// Checking out a remote branch creates a local one that tracks it.
49454947
writesSharedConfig: !localInputExists,

0 commit comments

Comments
 (0)