From 43a5a2023bac04aa18be1a7c833eeddcd21dc06e Mon Sep 17 00:00:00 2001 From: Eric Wagoner Date: Mon, 28 Sep 2026 13:43:15 -0400 Subject: [PATCH] dev:all stops both sides when the server's port is taken Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Jm2auWk6RP71CjaAb4FMoG --- scripts/dev-all.mjs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/scripts/dev-all.mjs b/scripts/dev-all.mjs index ac793ec..95f7708 100644 --- a/scripts/dev-all.mjs +++ b/scripts/dev-all.mjs @@ -1,5 +1,6 @@ // The game server and the site together, for playing locally: one terminal, -// each line marked with its side, and Ctrl-C (or either one stopping) stops both. +// each line marked with its side, and Ctrl-C (or either one stopping or +// failing to get its port) stops both. import { spawn } from 'node:child_process'; const sides = [ @@ -13,7 +14,14 @@ const children = sides.map(([name, args]) => { stream.on('data', (chunk) => { const lines = (rest + chunk).split('\n'); rest = lines.pop(); - for (const line of lines) console.log(`[${name}] ${line}`); + for (const line of lines) { + console.log(`[${name}] ${line}`); + // A watcher outlives the crash it watches, so a port already taken would leave one side running alone. + if (line.includes('EADDRINUSE')) { + console.log(`[${name}] its port is taken: is another copy already running?`); + stop(1); + } + } }); } child.on('exit', (code) => stop(code ?? 0));