Skip to content

Commit e1931b5

Browse files
vitalyiegorovclaudejuliusmarminge
authored
fix(server): keep a failed service start out of the current state (pingdotgg#12199)
Co-authored-by: Claude Fable 5.1 <[email protected]> Co-authored-by: Julius Marminge <[email protected]>
1 parent 09b464c commit e1931b5

2 files changed

Lines changed: 28 additions & 6 deletions

File tree

‎apps/server/src/cloud/bootService.test.ts‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -858,6 +858,32 @@ it.layer(NodeServices.layer)("boot service install", (it) => {
858858
}),
859859
);
860860

861+
it.effect("keeps failed launch agent installs pending until activation succeeds", () =>
862+
Effect.gen(function* () {
863+
const { service, fs, statePath, commands, control } = yield* makeHarness("darwin");
864+
const path = yield* Path.Path;
865+
const plan = yield* service.install();
866+
const markerPath = path.join(path.dirname(statePath), SERVICE_RESTART_PENDING_FILE);
867+
const bootstrap = `launchctl bootstrap gui/501 ${plan.unitPath}`;
868+
control.failCommand = bootstrap;
869+
870+
expect((yield* service.install().pipe(Effect.flip))._tag).toBe("BootServiceCommandError");
871+
expect(yield* service.status).toMatchObject({
872+
current: false,
873+
problems: ["restart-pending"],
874+
});
875+
expect(yield* fs.readFileString(markerPath)).toBe("1.2.3\n");
876+
877+
control.failCommand = undefined;
878+
commands.length = 0;
879+
yield* service.install();
880+
881+
expect(commands).toContain(bootstrap);
882+
expect(yield* fs.exists(markerPath)).toBe(false);
883+
expect((yield* service.status).current).toBe(true);
884+
}),
885+
);
886+
861887
it.effect("restarts without overwriting a pending remote update on macOS", () =>
862888
Effect.gen(function* () {
863889
const { service, fs, statePath, commands } = yield* makeHarness("darwin");

‎apps/server/src/cloud/bootService.ts‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -810,12 +810,8 @@ export const make = Effect.fn("cloud.boot_service.make")(function* (input: {
810810
yield* fs
811811
.makeDirectory(path.dirname(unitPath), { recursive: true })
812812
.pipe(Effect.mapError((cause) => new BootServiceInstallError({ cause })));
813-
if (!start && installed) {
814-
// Written first: once the files below name the new version, the running
815-
// service is behind them, and a failure between the two writes must not
816-
// leave it looking current.
817-
yield* fs.writeFileString(restartPendingPath, `${input.cliVersion}\n`, { mode: 0o600 });
818-
}
813+
// Files can match the new version even when activation fails; keep that install retryable.
814+
yield* fs.writeFileString(restartPendingPath, `${input.cliVersion}\n`, { mode: 0o600 });
819815
yield* writeDurably(
820816
statePath,
821817
// @effect-diagnostics-next-line preferSchemaOverJson:off - fixed launcher-owned document.

0 commit comments

Comments
 (0)