Skip to content

Commit 0fc8f4a

Browse files
t3dotggclaude
andcommitted
review: hold the install reservation until failed-install recovery completes
Co-Authored-By: Claude Fable 5 <[email protected]>
1 parent cb96a8e commit 0fc8f4a

3 files changed

Lines changed: 45 additions & 2 deletions

File tree

‎apps/desktop/src/updates/DesktopUpdates.test.ts‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,45 @@ describe("DesktopUpdates", () => {
587587
).pipe(Effect.provide(Layer.merge(TestClock.layer(), harness.layer)));
588588
});
589589

590+
it.effect("refuses a second install while a failed install is still recovering", () => {
591+
const backendRestarting = Deferred.makeUnsafe<void>();
592+
const releaseRestart = Deferred.makeUnsafe<void>();
593+
const harness = makeHarness({
594+
quitAndInstall: Effect.fail(
595+
new ElectronUpdater.ElectronUpdaterQuitAndInstallError({
596+
channel: "latest",
597+
isSilent: true,
598+
isForceRunAfter: true,
599+
cause: new Error("installer refused"),
600+
}),
601+
),
602+
startBackend: Deferred.succeed(backendRestarting, undefined).pipe(
603+
Effect.andThen(Deferred.await(releaseRestart)),
604+
),
605+
});
606+
607+
return Effect.scoped(
608+
Effect.gen(function* () {
609+
const updates = yield* DesktopUpdates.DesktopUpdates;
610+
yield* updates.configure;
611+
harness.emit("update-downloaded", { version: "1.2.4" });
612+
yield* flushCallbacks;
613+
614+
const first = yield* updates.install.pipe(Effect.forkChild);
615+
yield* Deferred.await(backendRestarting);
616+
// Recovery in flight: the reservation must still be held so a
617+
// concurrent install cannot stop the backends a second time.
618+
const second = yield* updates.install;
619+
assert.isFalse(second.accepted);
620+
assert.equal(harness.quitAndInstalls(), 1);
621+
622+
yield* Deferred.succeed(releaseRestart, undefined);
623+
assert.isTrue((yield* Fiber.join(first)).accepted);
624+
assert.deepEqual(harness.installSteps, ["quitAndInstall", "startBackend"]);
625+
}),
626+
).pipe(Effect.provide(Layer.merge(TestClock.layer(), harness.layer)));
627+
});
628+
590629
it.effect("recovers when quitAndInstall reports failure through an updater event", () => {
591630
const harness = makeHarness();
592631

‎apps/desktop/src/updates/DesktopUpdates.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,13 +508,16 @@ export const make = Effect.gen(function* () {
508508
const recoverFailedInstall = Effect.fn("desktop.updates.recoverFailedInstall")(function* (
509509
message: string,
510510
) {
511-
yield* resetInstallAction;
511+
// Hold the install reservation and `quitting` until recovery is done.
512+
// Releasing them first would let a concurrent install be admitted and
513+
// stop the backends again while they are still restarting.
512514
const instances = yield* pool.list;
513515
yield* Effect.forEach(instances, (instance) => instance.start, {
514516
concurrency: "unbounded",
515517
discard: true,
516518
});
517519
yield* updateState((current) => reduceDesktopUpdateStateOnInstallFailure(current, message));
520+
yield* resetInstallAction;
518521
});
519522

520523
const installDownloadedUpdate = (expectedVersion?: string) =>

‎apps/desktop/src/updates/updatesTestHarness.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export interface UpdatesHarnessOptions {
3030
readonly downloadUpdate?: Effect.Effect<void>;
3131
readonly quitAndInstall?: Effect.Effect<void, ElectronUpdater.ElectronUpdaterQuitAndInstallError>;
3232
readonly stopBackend?: Effect.Effect<void>;
33+
readonly startBackend?: Effect.Effect<void>;
3334
readonly env?: Record<string, string | undefined>;
3435
}
3536

@@ -126,7 +127,7 @@ export function makeHarness(options: UpdatesHarnessOptions = {}) {
126127
label: Effect.succeed("Windows"),
127128
start: Effect.sync(() => {
128129
installSteps.push("startBackend");
129-
}),
130+
}).pipe(Effect.andThen(options.startBackend ?? Effect.void)),
130131
stop: () => options.stopBackend ?? Effect.void,
131132
currentConfig: Effect.succeed(Option.none()),
132133
snapshot: Effect.succeed({

0 commit comments

Comments
 (0)