Skip to content

Commit f0ea416

Browse files
committed
fix: prevent server crash from SIGTERM and bind to 0.0.0.0
Server was being killed by external SIGTERM signals after startup. Ignore SIGTERM while server is running, allow graceful SIGINT exit. Bind to 0.0.0.0 explicitly for external IP access.
1 parent 3e3e06b commit f0ea416

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

src/cli.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
#!/usr/bin/env node
22

3+
let serverRunning = false;
4+
5+
process.on("SIGTERM", () => {
6+
if (serverRunning) return;
7+
process.exit(0);
8+
});
9+
10+
process.on("SIGINT", () => {
11+
process.exit(0);
12+
});
13+
314
process.on("uncaughtException", (err) => {
415
process.stderr.write(`Fatal: ${err.stack ?? err.message}\n`);
516
process.exit(1);
@@ -185,7 +196,7 @@ async function runServer(
185196

186197
function attempt(currentPort: number): void {
187198
attempts++;
188-
server.listen(currentPort, () => { resolve(); });
199+
server.listen(currentPort, "0.0.0.0", () => { resolve(); });
189200
server.on("error", (err: NodeJS.ErrnoException) => {
190201
if (err.code === "EADDRINUSE" && attempts < maxAttempts) {
191202
console.warn(`Port ${currentPort} in use, trying ${currentPort + 1}...`);
@@ -199,6 +210,7 @@ async function runServer(
199210
attempt(port);
200211
});
201212

213+
serverRunning = true;
202214
const actualPort = (server.address() as { port: number }).port;
203215
console.log(`3D map ready at http://localhost:${actualPort}`);
204216
}

0 commit comments

Comments
 (0)