Skip to content

Commit c94350d

Browse files
freddy-dclaude
andcommitted
fix(server): detect inherited bootstrap pipes on Windows
Node's Stats.isFIFO() is hardwired to false on Windows, so the desktop's fd3 pipe was read with fs.createReadStream. When the envelope never arrived, the timeout fired but the pending threadpool read kept the backend alive forever, so the desktop never restarted it. Check the S_IFIFO mode bits directly and run the real-pipe test on Windows too. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 4946281 commit c94350d

2 files changed

Lines changed: 23 additions & 21 deletions

File tree

‎apps/server/src/bootstrap.test.ts‎

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -236,31 +236,29 @@ it.layer(NodeServices.layer)("readBootstrapEnvelope", (it) => {
236236
});
237237

238238
// Real inherited pipe: an fs read would hold a threadpool thread and keep the process alive.
239-
it.live.skipIf(HostProcess.Platform.defaultValue() === "win32")(
240-
"times out and lets the process exit while the bootstrap pipe stays open",
241-
() =>
242-
Effect.promise(async () => {
243-
const child = NodeChildProcess.spawn(
244-
process.execPath,
245-
[
246-
"--input-type=module",
247-
"-e",
248-
`import * as Effect from "effect/Effect";
239+
it.live("times out and lets the process exit while the bootstrap pipe stays open", () =>
240+
Effect.promise(async () => {
241+
const child = NodeChildProcess.spawn(
242+
process.execPath,
243+
[
244+
"--input-type=module",
245+
"-e",
246+
`import * as Effect from "effect/Effect";
249247
import * as Schema from "effect/Schema";
250248
import { readBootstrapEnvelope } from "./src/bootstrap.ts";
251249
const exit = await Effect.runPromiseExit(
252250
readBootstrapEnvelope(Schema.String, 3, { timeoutMs: 50 }).pipe(Effect.flip),
253251
);
254252
console.log(exit._tag === "Success" ? exit.value._tag : "unexpected success");`,
255-
],
256-
{ cwd: `${import.meta.dirname}/..`, stdio: ["ignore", "pipe", "inherit", "pipe"] },
257-
);
258-
let stdout = "";
259-
child.stdout?.on("data", (chunk) => (stdout += chunk));
260-
const code = await new Promise((resolve) => child.once("exit", resolve));
261-
child.stdio[3]?.destroy();
253+
],
254+
{ cwd: `${import.meta.dirname}/..`, stdio: ["ignore", "pipe", "inherit", "pipe"] },
255+
);
256+
let stdout = "";
257+
child.stdout?.on("data", (chunk) => (stdout += chunk));
258+
const code = await new Promise((resolve) => child.once("exit", resolve));
259+
child.stdio[3]?.destroy();
262260

263-
assert.equal(stdout.trim(), "BootstrapEnvelopeTimeoutError");
264-
assert.equal(code, 0);
265-
}),
261+
assert.equal(stdout.trim(), "BootstrapEnvelopeTimeoutError");
262+
assert.equal(code, 0);
263+
}),
266264
);

‎apps/server/src/bootstrap.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export const readBootstrapEnvelope = Effect.fn("readBootstrapEnvelope")(function
102102
catch: (cause) => new BootstrapFdStatError({ fd, cause }),
103103
});
104104

105-
const stream = yield* makeBootstrapInputStream(fd, stat.isSocket() || stat.isFIFO());
105+
const stream = yield* makeBootstrapInputStream(fd, isPipeStat(stat));
106106

107107
// Covers slow cold starts while staying well under the desktop readiness timeout.
108108
const timeoutMs = options?.timeoutMs ?? 30_000;
@@ -173,6 +173,10 @@ export const readBootstrapEnvelope = Effect.fn("readBootstrapEnvelope")(function
173173
);
174174
});
175175

176+
// Node's Stats.isFIFO() is hardwired to false on Windows, where libuv reports pipes as S_IFIFO.
177+
const isPipeStat = (stat: NodeFS.Stats): boolean =>
178+
stat.isSocket() || (stat.mode & NodeFS.constants.S_IFMT) === NodeFS.constants.S_IFIFO;
179+
176180
const makeBootstrapInputStream = Effect.fn("bootstrap.makeBootstrapInputStream")(function* (
177181
fd: number,
178182
isPipe: boolean,

0 commit comments

Comments
 (0)