Restore dev sharing when lease handoff fails

This commit is contained in:
Theo Browne committed 2026-07-26 20:40:30 -07:00
1 parent 900173096d
commit 200774a710
2 files changed
+55 -6

No files matched your search

+23
View File
@@ -12,6 +12,7 @@ import {
claimDevShareLease,
cleanupOwnedDevShare,
type DevShareError,
DevShareLeaseClaimError,
DevServeFailedError,
shareDevServer,
unshareDevServer,
@@ -247,6 +248,28 @@ it.layer(NodeServices.layer)("dev share cleanup ownership", (it) => {
}),
);
it.effect("restores the mapping when ownership cannot be claimed", () =>
Effect.gen(function* () {
const fileSystem = yield* FileSystem.FileSystem;
const directory = yield* fileSystem.makeTempDirectoryScoped({
prefix: "t3-dev-share-lease-",
});
const blockedDirectory = `${directory}/not-a-directory`;
const calls: Array<ReadonlyArray<string>> = [];
yield* fileSystem.writeFileString(blockedDirectory, "blocked");
const error = yield* acquireDevShare({
leasePath: `${blockedDirectory}/5788.owner`,
ownerId: "new-runner",
webPort: 5788,
}).pipe(Effect.provide(spawnerLayer({ calls })), Effect.flip);
assert.instanceOf(error, DevShareLeaseClaimError);
assert.isTrue(calls.some((args) => args.includes("off")));
assert.isTrue(calls.some((args) => args.includes("http://127.0.0.1:5788")));
}),
);
it.effect("restores a newer runner's mapping when ownership changes during cleanup", () =>
Effect.gen(function* () {
const fileSystem = yield* FileSystem.FileSystem;
+32 -6
View File
@@ -115,14 +115,22 @@ export class DevServeFailedError extends Schema.TaggedErrorClass<DevServeFailedE
export class DevShareLeaseClaimError extends Schema.TaggedErrorClass<DevShareLeaseClaimError>()(
"DevShareLeaseClaimError",
{ leasePath: Schema.String, cause: Schema.Defect() },
{
leasePath: Schema.String,
cause: Schema.Defect(),
restoreCause: Schema.optional(Schema.Defect()),
},
) {
override get message(): string {
return `could not claim cleanup ownership at ${this.leasePath}`;
return this.restoreCause === undefined
? `could not claim cleanup ownership at ${this.leasePath}`
: `could not claim cleanup ownership at ${this.leasePath} or restore the previous tailnet mapping`;
}
get hint(): string {
return "Check that the dev data directory is writable.";
return this.restoreCause === undefined
? "Check that the dev data directory is writable."
: "Check that the dev data directory is writable, then run the share command again.";
}
}
@@ -333,7 +341,25 @@ export const shareDevServer = Effect.fn("devShare.shareDevServer")(function* (in
export const acquireDevShare = Effect.fn("devShare.acquireDevShare")(function* (
lease: DevShareLease,
) {
const host = yield* prepareDevShare({ webPort: lease.webPort });
yield* claimDevShareLease(lease);
return yield* publishDevShare({ host, webPort: lease.webPort });
return yield* Effect.gen(function* () {
const host = yield* prepareDevShare({ webPort: lease.webPort });
yield* claimDevShareLease(lease).pipe(
Effect.catch((error: DevShareLeaseClaimError) =>
publishDevShare({ host, webPort: lease.webPort }).pipe(
Effect.matchEffect({
onFailure: (restoreCause) =>
Effect.fail(
new DevShareLeaseClaimError({
leasePath: lease.leasePath,
cause: error.cause,
restoreCause,
}),
),
onSuccess: () => Effect.fail(error),
}),
),
),
);
return yield* publishDevShare({ host, webPort: lease.webPort });
}).pipe(Effect.uninterruptible);
});