From c5a3f6907a115ea2d511b0aa9905a2e762514867 Mon Sep 17 00:00:00 2001 From: Mariusz Nowak Date: Wed, 7 Jul 2021 15:33:17 +0200 Subject: [PATCH] fix(CLI): Fix `SIGINT` signal handling --- scripts/serverless.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/scripts/serverless.js b/scripts/serverless.js index 0a58281aa..2a2570352 100755 --- a/scripts/serverless.js +++ b/scripts/serverless.js @@ -55,8 +55,11 @@ process.once('uncaughtException', (error) => { }); }); -process.on('SIGINT', () => { +process.once('SIGINT', () => { clearTimeout(keepAliveTimer); + // If there's another SIGINT listener (command that works as deamon or reads stdin input) + // then let the other listener decide how process will exit + const isOtherSigintListener = Boolean(process.listenerCount('SIGINT')); if ( commandSchema && !hasTelemetryBeenReported && @@ -74,7 +77,7 @@ process.on('SIGINT', () => { }); storeTelemetryLocally({ ...telemetryPayload, outcome: 'interrupt' }); } - process.exit(1); + if (!isOtherSigintListener) process.exit(130); }); const processSpanPromise = (async () => {