Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): a desktop backend whose launcher died shuts down cleanly instead of crashing #22471

MergedSunkenInTime(GitHub profile, opens in a new tab)merged 1 commit intomain fromrefs/pull/22471/headmerged by t3dotgg(GitHub profile, opens in a new tab) View on GitHub

Showing 1 changed file with 11 additions and 0 deletions.

x
0 of 1 viewed, 1 left
11 additions and 0 deletionsapps/server/src/cli/server.tsModified
View file
@@ -13,6 +13,13 @@
​
const 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 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(