From a4341e7e607456b829575e47c3e42afe5bc96b18 Mon Sep 17 00:00:00 2001 From: Melvin Carvalho Date: Mon, 25 May 2026 21:48:14 +0200 Subject: [PATCH] fix(shutdown): stop Ctrl+C output racing the shell prompt The JSS child shares the CLI's process group, so a terminal Ctrl+C delivers SIGINT to both. The child already prints "Shutting down..." and exits on its own; the CLI was also printing "Shutting down gracefully..." and then racing the farewell against the returning shell prompt. Drop the parent's redundant line and let handle.stop() await the child's exit before the farewell, so output stays ordered. Same process group, so closing the terminal still tears the server down (no detached orphan). Closes #62 --- index.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index c327a68..6121670 100755 --- a/index.js +++ b/index.js @@ -519,12 +519,15 @@ handle.exit.then(({ code, signal }) => { } }); -// Graceful shutdown +// Graceful shutdown. The JSS child shares our process group, so a terminal +// Ctrl+C delivers SIGINT to it too — it prints its own "Shutting down..." +// and exits. We don't duplicate that line; we just await its exit (which +// handle.stop() does) and then print the farewell, so the output stays +// ordered ahead of the returning shell prompt instead of racing it. process.on('SIGINT', async () => { - console.log('\n' + chalk.yellow('⚠ Shutting down gracefully...')); await handle.stop(); - console.log(chalk.green('āœ“ Server stopped')); - console.log(chalk.dim('\nGoodbye! šŸ‘‹\n')); + console.log(chalk.green('\nāœ“ Server stopped')); + console.log(chalk.dim('Goodbye! šŸ‘‹\n')); process.exit(0); });