GeezerVison is showing github.com — fix(server): skip status fetch cleanup when the pack listing fails · pingdotgg/t3code@e00514e
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/server/src/vcs/GitVcsDriverCore.test.ts +34-2Lines changed: 34 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -821,7 +821,18 @@ it.effect("backs off and logs failed fetch attempts across linked worktrees", () | 821 | 821 | ).pipe(Effect.provide(layerServerConfig.pipe(Layer.provideMerge(NodeServices.layer)))), | 822 | 822 | ); | 823 | 823 |
| 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 }) => | 825 | 836 | Effect.scoped( | 826 | 837 | Effect.gen(function* () { | 827 | 838 | const delegate = yield* ChildProcessSpawner.ChildProcessSpawner; | @@ -831,6 +842,25 @@ it.effect("removes the partial pack a timed-out status fetch leaves behind", () | 831 | 842 | const remote = yield* makeTmpDir("git-vcs-driver-remote-"); | 832 | 843 | const packDir = pathService.join(cwd, ".git", "objects", "pack"); | 833 | 844 | 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; | 834 | 864 | // Stands in for a fetch whose index-pack is still writing when the timeout kills it. | 835 | 865 | const hangingFetchSpawner = ChildProcessSpawner.make((command) => | 836 | 866 | Effect.gen(function* () { | @@ -859,6 +889,7 @@ it.effect("removes the partial pack a timed-out status fetch leaves behind", () | 859 | 889 | ); | 860 | 890 | const driver = yield* makeGitVcsDriverCore().pipe( | 861 | 891 | Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, hangingFetchSpawner), | | 892 | + Effect.provideService(FileSystem.FileSystem, flakyFileSystem), | 862 | 893 | ); | 863 | 894 | const runGit = (workingDirectory: string, args: ReadonlyArray<string>) => | 864 | 895 | driver.execute({ | @@ -880,6 +911,7 @@ it.effect("removes the partial pack a timed-out status fetch leaves behind", () | 880 | 911 | yield* runGit(cwd, ["push", "-u", "origin", initialBranch]); | 881 | 912 | // A partial pack that was already there belongs to some other fetch and must survive. | 882 | 913 | yield* fileSystem.writeFileString(pathService.join(packDir, "tmp_pack_other"), ""); | | 914 | + yield* Ref.set(failNextPackListing, baselineListingFails); | 883 | 915 |
| 884 | 916 | const status = yield* driver.statusDetailsRemote(cwd).pipe(Effect.forkChild); | 885 | 917 | yield* Deferred.await(fetchStarted); | @@ -889,7 +921,7 @@ it.effect("removes the partial pack a timed-out status fetch leaves behind", () | 889 | 921 | const temporaryPacks = (yield* fileSystem.readDirectory(packDir)).filter((name) => | 890 | 922 | name.startsWith("tmp_"), | 891 | 923 | ); | 892 | | - assert.deepStrictEqual(temporaryPacks, ["tmp_pack_other"]); | | 924 | + assert.deepStrictEqual(temporaryPacks.toSorted(), expected); | 893 | 925 | }), | 894 | 926 | ).pipe(Effect.provide(layerServerConfig.pipe(Layer.provideMerge(NodeServices.layer)))), | 895 | 927 | ); | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/vcs/GitVcsDriverCore.ts +19-11Lines changed: 19 additions & 11 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1206,11 +1206,14 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function* | 1206 | 1206 | ); | 1207 | 1207 | }); | 1208 | 1208 |
| 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. | 1210 | 1211 | const listTemporaryPackFiles = (packDir: string) => | 1211 | 1212 | fileSystem.readDirectory(packDir).pipe( | 1212 | 1213 | 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 | + ), | 1214 | 1217 | ); | 1215 | 1218 |
| 1216 | 1219 | const fetchRemoteForStatus = ( | @@ -1226,8 +1229,10 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function* | 1226 | 1229 | // behind each time, so a background poll could fill the disk. | 1227 | 1230 | // A fetch killed by the timeout also leaves its partial `tmp_pack_*` behind, even on | 1228 | 1231 | // 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. | 1230 | 1234 | return listTemporaryPackFiles(packDir).pipe( | | 1235 | + Effect.option, | 1231 | 1236 | Effect.flatMap((existing) => | 1232 | 1237 | executeGit( | 1233 | 1238 | "GitVcsDriver.fetchRemoteForStatus", | @@ -1240,15 +1245,18 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function* | 1240 | 1245 | }, | 1241 | 1246 | ).pipe( | 1242 | 1247 | 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, | 1249 | 1259 | ), | 1250 | | - ), | 1251 | | - ), | 1252 | 1260 | ), | 1253 | 1261 | ), | 1254 | 1262 | ), | |
|