TypeScript
fix(server): remote updates no longer fail when the staged preflight is slow on a loaded host (#28201)
Julius Marmingeda2d6ec2c881
diff --git a/apps/server/src/cloud/selfUpdate.test.ts b/apps/server/src/cloud/selfUpdate.test.tsindex 8070ea2af73..9e1aee9c095 100644--- a/apps/server/src/cloud/selfUpdate.test.ts+++ b/apps/server/src/cloud/selfUpdate.test.ts@@ -3,6 +3,7 @@ import { expect, it } from "@effect/vitest";import type { ManagedPolicyDocument } from "@t3tools/contracts";import * as HostProcess from "@t3tools/shared/HostProcess";import * as Deferred from "effect/Deferred";+import * as Duration from "effect/Duration";import * as Effect from "effect/Effect";import * as FileSystem from "effect/FileSystem";import * as Fiber from "effect/Fiber";@@ -26,6 +27,8 @@ interface HarnessOptions {readonly mode?: "web" | "desktop";readonly managed?: boolean;readonly preflight?: "ready" | "blocked";+ readonly preflightDuration?: Duration.Input;+ readonly preflightStarted?: Deferred.Deferred<void>;readonly beforeDownload?: Effect.Effect<void>;readonly requestUpdate?: ServiceLauncherClient.ServiceLauncherClient["Service"]["requestUpdate"];readonly desktopAppUpdate?: DesktopAppUpdate.DesktopAppUpdate["Service"];@@ -78,6 +81,21 @@ const makeHarness = Effect.fn("test.make_self_update_harness")(function* (stderrInvalidUtf8: false,};}+ if (options.preflightStarted) yield* Deferred.succeed(options.preflightStarted, undefined);+ if (options.preflightDuration !== undefined) {+ // Like the real runner, fail once the caller's timeout elapses.+ const timeout = Duration.fromInputUnsafe(input.timeout ?? "60 seconds");+ const finished = yield* Effect.sleep(options.preflightDuration).pipe(+ Effect.timeoutOption(timeout),+ );+ if (finished._tag === "None") {+ return yield* new ProcessRunner.ProcessTimeoutError({+ command: input.command,+ argumentCount: input.args.length,+ timeoutMs: Duration.toMillis(timeout),+ });+ }+ }order.push("preflight");const result =options.preflight === "blocked"@@ -240,6 +258,27 @@ it.layer(NodeServices.layer)("server self update", (it) => {}),);+ // regression: #28198 a slow staged preflight on a loaded host no longer fails the update+ it.effect("waits for a staged preflight that takes a minute on a loaded host", () =>+ Effect.gen(function* () {+ const preflightStarted = yield* Deferred.make<void>();+ const { selfUpdate, order } = yield* makeHarness({+ preflightDuration: "60 seconds",+ preflightStarted,+ });+ const update = yield* Effect.forkChild(selfUpdate.update({ targetVersion: "1.1.0" }), {+ startImmediately: true,+ });+ yield* Deferred.await(preflightStarted);+ yield* TestClock.adjust("60 seconds");+ const exit = yield* Fiber.await(update);+ expect(exit._tag === "Failure" ? String(exit.cause) : "launcher handoff").toBe(+ "launcher handoff",+ );+ expect(order).toEqual(["download", "extract", "preflight", "accept"]);+ }),+ );+it.effect("keeps preparing after the progress stream closes", () =>Effect.gen(function* () {const releaseDownload = yield* Deferred.make<void>();diff --git a/apps/server/src/cloud/selfUpdate.ts b/apps/server/src/cloud/selfUpdate.tsindex 67e3e1f9413..1f285b9b652 100644--- a/apps/server/src/cloud/selfUpdate.ts+++ b/apps/server/src/cloud/selfUpdate.ts@@ -45,7 +45,8 @@ import { decodeServicePreflightResult } from "./servicePreflight.ts";import * as ServiceLauncherClient from "./serviceLauncherClient.ts";import { isExactServiceVersion, SERVICE_LAUNCHER_PROTOCOL } from "./serviceProtocol.ts";-const PREFLIGHT_TIMEOUT = Duration.seconds(30);+// A staged runtime's cold start can take over a minute on a loaded, swapping host.+const PREFLIGHT_TIMEOUT = Duration.minutes(3);export function resolveServerSelfUpdateCapability(input: {readonly desktopManaged: boolean;