Skip to content

Commit 1ef478e

Browse files
committed
don't detach server
1 parent 73e2cfe commit 1ef478e

2 files changed

Lines changed: 14 additions & 22 deletions

File tree

‎.changeset/late-cameras-open.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"executor": patch
3+
---
4+
5+
Don't detach server

‎apps/cli/src/main.ts‎

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ if (typeof Bun !== "undefined" && await Bun.file(wasmOnDisk).exists()) {
1818
setQuickJSModule(mod);
1919
}
2020

21-
import { spawn } from "node:child_process";
2221
import { resolve } from "node:path";
2322
import { Command, Options, Args } from "@effect/cli";
2423
import { BunRuntime } from "@effect/platform-bun";
@@ -74,33 +73,16 @@ const script = process.argv[1];
7473
const isDevMode = script?.endsWith(".ts") || script?.endsWith(".js");
7574
const cliPrefix = isDevMode ? `bun run ${script}` : "executor";
7675

77-
const startBackgroundServer = (port: number): void => {
78-
const args = isDevMode
79-
? ["run", script, "web", "--port", String(port)]
80-
: ["web", "--port", String(port)];
81-
const child = spawn(process.execPath, args, {
82-
detached: true,
83-
stdio: "ignore",
84-
});
85-
child.unref();
86-
};
87-
8876
const ensureServer = (baseUrl: string) =>
8977
Effect.gen(function* () {
9078
if (yield* Effect.promise(() => isServerReachable(baseUrl))) return;
9179

80+
// Start server in-process instead of spawning a background child.
81+
// This is more reliable across environments (containers, sandboxes, etc.)
9282
const url = new URL(baseUrl);
9383
const port = Number(url.port) || DEFAULT_PORT;
94-
console.error(`Starting background server on port ${port}...`);
95-
startBackgroundServer(port);
96-
97-
const deadline = Date.now() + 30_000;
98-
while (Date.now() < deadline) {
99-
yield* Effect.promise(() => new Promise((r) => setTimeout(r, 200)));
100-
if (yield* Effect.promise(() => isServerReachable(baseUrl))) return;
101-
}
102-
103-
return yield* Effect.fail(new Error(`Server failed to start within 30s at ${baseUrl}`));
84+
console.error(`Starting server on port ${port}...`);
85+
yield* Effect.promise(() => startServer({ port, embeddedWebUI }));
10486
});
10587

10688
// ---------------------------------------------------------------------------
@@ -302,6 +284,11 @@ const runCli = Command.run(root, {
302284
executable: CLI_NAME,
303285
});
304286

287+
if (process.argv.includes("-v")) {
288+
console.log(CLI_VERSION);
289+
process.exit(0);
290+
}
291+
305292
const program = runCli(process.argv).pipe(
306293
Effect.catchAllCause((cause) =>
307294
Effect.sync(() => {

0 commit comments

Comments
 (0)