Skip to content

Commit bf59c69

Browse files
fix(cli): keep the deferred-restart marker until a launcher of that version starts
Co-Authored-By: Claude Fable 5 <[email protected]>
1 parent 0b1ed14 commit bf59c69

2 files changed

Lines changed: 28 additions & 10 deletions

File tree

‎apps/server/src/serviceLauncher.test.ts‎

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,15 +133,27 @@ it.layer(NodeServices.layer)("service state persistence", (it) => {
133133
activeVersion: "1.0.0",
134134
}),
135135
);
136-
yield* fs.writeFileString(restartPending, "1.0.0\n");
136+
const run = () =>
137+
Effect.gen(function* () {
138+
const launcher = new Launcher(
139+
root,
140+
yield* Effect.promise(() => readServiceState(statePath)),
141+
);
142+
const running = launcher.run();
143+
yield* Effect.promise(() => launcher.stop("SIGTERM"));
144+
yield* Effect.promise(() => running);
145+
});
146+
147+
// A launcher that is still the old version leaves a marker that waits
148+
// for a newer one.
149+
yield* fs.writeFileString(restartPending, "1.0.1\n");
150+
yield* run();
151+
assert.isTrue(yield* fs.exists(restartPending));
137152

138-
const launcher = new Launcher(root, yield* Effect.promise(() => readServiceState(statePath)));
139-
const running = launcher.run();
140-
const stopping = launcher.stop("SIGTERM");
141-
yield* Effect.promise(() => stopping);
142-
yield* Effect.promise(() => running);
143153
// Whoever restarted the service, the launcher now runs what the unit
144154
// names, so the deferred-restart marker is gone.
155+
yield* fs.writeFileString(restartPending, "1.0.0\n");
156+
yield* run();
145157
assert.isFalse(yield* fs.exists(restartPending));
146158
}),
147159
);

‎apps/server/src/serviceLauncher.ts‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -368,11 +368,17 @@ export class Launcher {
368368
async #recover(): Promise<void> {
369369
// A fresh launcher means servers are running again: any stop marker from
370370
// a previous explicit stop is stale and must not make a future update
371-
// handoff release its tunnel. A fresh launcher is also, by definition,
372-
// the one the unit names, so a restart deferred by `t3 update` is done
373-
// no matter who restarted the service.
371+
// handoff release its tunnel. A restart deferred by `t3 update` is done
372+
// no matter who restarted the service, but only once this launcher is
373+
// the version the marker waits for: a launcher that came up between the
374+
// CLI writing the marker and writing the new state still runs the old
375+
// version, and the marker has to outlive it.
374376
await NodeFSP.rm(stopMarkerPath(this.#baseDir), { force: true }).catch(() => undefined);
375-
await NodeFSP.rm(restartPendingPath(this.#baseDir), { force: true }).catch(() => undefined);
377+
const restartPending = restartPendingPath(this.#baseDir);
378+
const awaitedVersion = await NodeFSP.readFile(restartPending, "utf8").catch(() => undefined);
379+
if (awaitedVersion?.trim() === this.#state.activeVersion) {
380+
await NodeFSP.rm(restartPending, { force: true }).catch(() => undefined);
381+
}
376382
const update = this.#state.update;
377383
if (update?.status !== "pending") {
378384
if (update !== undefined) {

0 commit comments

Comments
 (0)