History

don't detach server

Rhys Sullivan committed 7 months ago

Commit 1ef478e1 parent 73e2cfe2 files · +14 −22Browse files

Unified · Split

2 files
  1. .changeset/late-cameras-open.md +5 −0
  2. apps/cli/src/main.ts +9 −22
.changeset/late-cameras-open.md+5−0
@@ -0,0 +1,5 @@
1+---
2+"executor": patch
3+---
4+
5+Don't detach server
apps/cli/src/main.ts+9−22
@@ -18,7 +18,6 @@ if (typeof Bun !== "undefined" && await Bun.file(wasmOnDisk).exists()) { · 17 unmodified lines
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]; · 49 unmodified lines
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, { · 195 unmodified lines
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(() => {