TypeScript
fix(server): a desktop backend whose launcher died shuts down cleanly instead of crashing (#22471)
Dara Adedeji2936b90883b2
diff --git a/apps/server/src/cli/server.ts b/apps/server/src/cli/server.tsindex e9f0d7e19ae..fee427cc7fa 100644--- a/apps/server/src/cli/server.ts+++ b/apps/server/src/cli/server.ts@@ -13,6 +13,13 @@ import { type CliServerFlags, resolveServerConfig, sharedServerCommandFlags } frconst encodeCommand = Schema.encodeEffect(Schema.fromJsonString(Schema.String));+// The desktop launcher reads this process's stdout and stderr. Once it is gone,+// every log write fails, and Node turns an unhandled stream error into a crash+// that skips shutdown and leaves the ownership lock and runtime record behind.+function ignoreClosedLauncherPipe(error: NodeJS.ErrnoException): void {+ if (error.code !== "EPIPE" && error.code !== "ERR_STREAM_DESTROYED") throw error;+}+const runServerCommand = Effect.fn("server.runServerCommand")(function* (flags: CliServerFlags,options?: {@@ -25,6 +32,10 @@ const runServerCommand = Effect.fn("server.runServerCommand")(function* (const config = yield* resolveServerConfig(flags, logLevel, options);const run = runServer.pipe(Effect.provideService(ServerConfig.ServerConfig, config));if (config.mode !== "desktop" || config.desktopBootstrapToken === undefined) return yield* run;+ yield* Effect.sync(() => {+ process.stdout.on("error", ignoreClosedLauncherPipe);+ process.stderr.on("error", ignoreClosedLauncherPipe);+ });return yield* Effect.raceFirst(run,awaitLauncherLoss().pipe(