GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(server): skip status fetch cleanup when the pack listing fails · pingdotgg/t3code@e00514e

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps/server/src/vcs
    • GitVcsDriverCore.test.ts
    • GitVcsDriverCore.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: apps/server/src/vcs/GitVcsDriverCore.test.ts
+34-2Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,18 @@ it.effect("backs off and logs failed fetch attempts across linked worktrees", ()
821821
).pipe(Effect.provide(layerServerConfig.pipe(Layer.provideMerge(NodeServices.layer)))),
822822
);
823823

824-
it.effect("removes the partial pack a timed-out status fetch leaves behind", () =>
824+
it.effect.each([
825+
{
826+
name: "removes the partial pack a timed-out status fetch leaves behind",
827+
baselineListingFails: false,
828+
expected: ["tmp_pack_other"],
829+
},
830+
{
831+
name: "keeps every partial pack when the pre-fetch listing fails",
832+
baselineListingFails: true,
833+
expected: ["tmp_pack_other", "tmp_pack_timed_out"],
834+
},
835+
])("$name", ({ baselineListingFails, expected }) =>
825836
Effect.scoped(
826837
Effect.gen(function* () {
827838
const delegate = yield* ChildProcessSpawner.ChildProcessSpawner;
@@ -831,6 +842,25 @@ it.effect("removes the partial pack a timed-out status fetch leaves behind", ()
831842
const remote = yield* makeTmpDir("git-vcs-driver-remote-");
832843
const packDir = pathService.join(cwd, ".git", "objects", "pack");
833844
const fetchStarted = yield* Deferred.make<void>();
845+
const failNextPackListing = yield* Ref.make(false);
846+
// Fails one pack directory listing on demand, like a transient EMFILE or EACCES.
847+
const flakyFileSystem = {
848+
...fileSystem,
849+
readDirectory: (directory, options) =>
850+
Effect.gen(function* () {
851+
// The driver lists the real path of the pack directory, so match its suffix.
852+
const isPackDir = directory.endsWith(pathService.join(".git", "objects", "pack"));
853+
if (isPackDir && (yield* Ref.getAndSet(failNextPackListing, false))) {
854+
return yield* PlatformError.systemError({
855+
_tag: "PermissionDenied",
856+
module: "FileSystem",
857+
method: "readDirectory",
858+
pathOrDescriptor: directory,
859+
});
860+
}
861+
return yield* fileSystem.readDirectory(directory, options);
862+
}),
863+
} satisfies FileSystem.FileSystem;
834864
// Stands in for a fetch whose index-pack is still writing when the timeout kills it.
835865
const hangingFetchSpawner = ChildProcessSpawner.make((command) =>
836866
Effect.gen(function* () {
@@ -859,6 +889,7 @@ it.effect("removes the partial pack a timed-out status fetch leaves behind", ()
859889
);
860890
const driver = yield* makeGitVcsDriverCore().pipe(
861891
Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, hangingFetchSpawner),
892+
Effect.provideService(FileSystem.FileSystem, flakyFileSystem),
862893
);
863894
const runGit = (workingDirectory: string, args: ReadonlyArray<string>) =>
864895
driver.execute({
@@ -880,6 +911,7 @@ it.effect("removes the partial pack a timed-out status fetch leaves behind", ()
880911
yield* runGit(cwd, ["push", "-u", "origin", initialBranch]);
881912
// A partial pack that was already there belongs to some other fetch and must survive.
882913
yield* fileSystem.writeFileString(pathService.join(packDir, "tmp_pack_other"), "");
914+
yield* Ref.set(failNextPackListing, baselineListingFails);
883915

884916
const status = yield* driver.statusDetailsRemote(cwd).pipe(Effect.forkChild);
885917
yield* Deferred.await(fetchStarted);
@@ -889,7 +921,7 @@ it.effect("removes the partial pack a timed-out status fetch leaves behind", ()
889921
const temporaryPacks = (yield* fileSystem.readDirectory(packDir)).filter((name) =>
890922
name.startsWith("tmp_"),
891923
);
892-
assert.deepStrictEqual(temporaryPacks, ["tmp_pack_other"]);
924+
assert.deepStrictEqual(temporaryPacks.toSorted(), expected);
893925
}),
894926
).pipe(Effect.provide(layerServerConfig.pipe(Layer.provideMerge(NodeServices.layer)))),
895927
);
Collapse file

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

Copy file name to clipboardExpand all lines: apps/server/src/vcs/GitVcsDriverCore.ts
+19-11Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,11 +1206,14 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
12061206
);
12071207
});
12081208

1209-
// Git's in-progress pack files (`tmp_pack_*`, `tmp_idx_*`) in a pack directory.
1209+
// Git's in-progress pack files (`tmp_pack_*`, `tmp_idx_*`) in a pack directory. A missing
1210+
// directory has none; other read failures are returned to the caller.
12101211
const listTemporaryPackFiles = (packDir: string) =>
12111212
fileSystem.readDirectory(packDir).pipe(
12121213
Effect.map((names) => names.filter((name) => name.startsWith("tmp_"))),
1213-
Effect.orElseSucceed((): ReadonlyArray<string> => []),
1214+
Effect.catchReason("PlatformError", "NotFound", () =>
1215+
Effect.succeed<ReadonlyArray<string>>([]),
1216+
),
12141217
);
12151218

12161219
const fetchRemoteForStatus = (
@@ -1226,8 +1229,10 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
12261229
// behind each time, so a background poll could fill the disk.
12271230
// A fetch killed by the timeout also leaves its partial `tmp_pack_*` behind, even on
12281231
// SIGTERM. Until one fetch fits in the timeout, every retry downloads the backlog again, so
1229-
// a failed fetch removes the temporary pack files that appeared while it ran.
1232+
// a failed fetch removes the temporary pack files that appeared while it ran. Without a
1233+
// baseline listing it cannot tell which files those are, so it removes nothing.
12301234
return listTemporaryPackFiles(packDir).pipe(
1235+
Effect.option,
12311236
Effect.flatMap((existing) =>
12321237
executeGit(
12331238
"GitVcsDriver.fetchRemoteForStatus",
@@ -1240,15 +1245,18 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
12401245
},
12411246
).pipe(
12421247
Effect.onError(() =>
1243-
listTemporaryPackFiles(packDir).pipe(
1244-
Effect.flatMap((current) =>
1245-
Effect.forEach(
1246-
current.filter((name) => !existing.includes(name)),
1247-
(name) => fileSystem.remove(path.join(packDir, name)).pipe(Effect.ignore),
1248-
{ discard: true },
1248+
Option.isNone(existing)
1249+
? Effect.void
1250+
: listTemporaryPackFiles(packDir).pipe(
1251+
Effect.flatMap((current) =>
1252+
Effect.forEach(
1253+
current.filter((name) => !existing.value.includes(name)),
1254+
(name) => fileSystem.remove(path.join(packDir, name)).pipe(Effect.ignore),
1255+
{ discard: true },
1256+
),
1257+
),
1258+
Effect.ignore,
12491259
),
1250-
),
1251-
),
12521260
),
12531261
),
12541262
),

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.