From a2d108838e2650161a5a6c43696a1f6263a5b9ae Mon Sep 17 00:00:00 2001 From: Hypatia May Date: Mon, 27 Jul 2026 15:49:43 +0800 Subject: [PATCH] fix(cli): install shutdown handlers before readiness --- apps/cli/src/web.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/apps/cli/src/web.ts b/apps/cli/src/web.ts index 31282c8f5f..29bddf840d 100644 --- a/apps/cli/src/web.ts +++ b/apps/cli/src/web.ts @@ -48,13 +48,15 @@ export async function runWeb( void Promise.resolve(ctx.fiber.dispose()).finally(() => { process.exit(code) }) } + // Install shutdown handling before publishing readiness: supervisors may + // send a signal as soon as they observe the URL line. + process.on('SIGTERM', () => { shutdown(0) }) + process.on('SIGINT', () => { shutdown(130) }) + const lanCandidate = host === ALL_INTERFACES_HOST ? Object.values(networkInterfaces()).flat() .find(iface => iface !== undefined && iface.family === 'IPv4' && !iface.internal) : undefined const localUrl = `http://${LOOPBACK_HOST}:${boundPort}` console.log(`dsh web: ${localUrl}${lanCandidate === undefined ? '' : ` (LAN: http://${lanCandidate.address}:${boundPort})`}`) - - process.on('SIGTERM', () => { shutdown(0) }) - process.on('SIGINT', () => { shutdown(130) }) }