Skip to content

Commit 4b33ef8

Browse files
committed
fix(desktop): restart backends if update install fails
Install still stops backends before quitAndInstall. If that last step fails, the window stayed up but the pool was already down, so the UI was disconnected. On install failure, start the stopped backends again.
1 parent 7f40bda commit 4b33ef8

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,9 @@ function makeHarness(options: UpdatesHarnessOptions = {}) {
123123
const stubBackendInstance: DesktopBackendPool.DesktopBackendInstance = {
124124
id: DesktopBackendPool.PRIMARY_INSTANCE_ID,
125125
label: Effect.succeed("Windows"),
126-
start: Effect.void,
126+
start: Effect.sync(() => {
127+
installSteps.push("startBackend");
128+
}),
127129
stop: () => options.stopBackend ?? Effect.void,
128130
currentConfig: Effect.succeed(Option.none()),
129131
snapshot: Effect.succeed({
@@ -774,7 +776,7 @@ describe("DesktopUpdates", () => {
774776
assert.isTrue(result.accepted);
775777
assert.isFalse(result.completed);
776778
assert.isFalse(yield* Ref.get(desktopState.quitting));
777-
assert.deepEqual(harness.installSteps, ["quitAndInstall"]);
779+
assert.deepEqual(harness.installSteps, ["quitAndInstall", "startBackend"]);
778780

779781
const failedState = yield* updates.getState;
780782
assert.equal(failedState.status, "downloaded");

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,11 @@ export const make = Effect.gen(function* () {
483483

484484
yield* Ref.set(desktopState.quitting, true);
485485

486+
const instances = yield* pool.list;
487+
const restartStoppedBackends = Effect.forEach(instances, (instance) => instance.start, {
488+
concurrency: "unbounded",
489+
}).pipe(Effect.asVoid);
490+
486491
return yield* Effect.gen(function* () {
487492
// Stop every backend in the pool, not just the primary. With
488493
// parallel WSL + Windows backends, leaving the WSL instance up
@@ -491,7 +496,6 @@ export const make = Effect.gen(function* () {
491496
// WSL child gets hard-killed by the OS instead of receiving
492497
// SIGTERM + grace. Stops run concurrently with the same 5s
493498
// budget the primary had on its own.
494-
const instances = yield* pool.list;
495499
yield* Effect.forEach(
496500
instances,
497501
(instance) => instance.stop({ timeout: Duration.seconds(5) }),
@@ -510,6 +514,7 @@ export const make = Effect.gen(function* () {
510514
ElectronUpdaterQuitAndInstallError: Effect.fn("desktop.updates.handleInstallFailure")(
511515
function* (error) {
512516
yield* resetInstallAction;
517+
yield* restartStoppedBackends;
513518
yield* updateState((current) =>
514519
reduceDesktopUpdateStateOnInstallFailure(current, error.message),
515520
);
@@ -530,6 +535,7 @@ export const make = Effect.gen(function* () {
530535
return yield* Effect.failCause(cause);
531536
}
532537
yield* resetInstallAction;
538+
yield* restartStoppedBackends;
533539
const error = new DesktopUpdateUnexpectedActionError({ action: "install", cause });
534540
yield* updateState((current) =>
535541
reduceDesktopUpdateStateOnInstallFailure(current, error.message),

0 commit comments

Comments
 (0)