From c5effca7d47a713f157eea21d7892002e9ab7283 Mon Sep 17 00:00:00 2001 From: Tomi Turtiainen <10324676+tomi@users.noreply.github.com> Date: Tue, 10 Dec 2024 13:00:18 +0200 Subject: [PATCH] fix(core): Make sure task runner exits (#12123) --- packages/@n8n/task-runner/src/start.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/@n8n/task-runner/src/start.ts b/packages/@n8n/task-runner/src/start.ts index f68779f38d..a419699204 100644 --- a/packages/@n8n/task-runner/src/start.ts +++ b/packages/@n8n/task-runner/src/start.ts @@ -11,7 +11,7 @@ let runner: JsTaskRunner | undefined; let isShuttingDown = false; let errorReporter: ErrorReporter | undefined; -function createSignalHandler(signal: string) { +function createSignalHandler(signal: string, timeoutInS = 10) { return async function onSignal() { if (isShuttingDown) { return; @@ -19,6 +19,11 @@ function createSignalHandler(signal: string) { console.log(`Received ${signal} signal, shutting down...`); + setTimeout(() => { + console.error('Shutdown timeout reached, forcing shutdown...'); + process.exit(1); + }, timeoutInS * 1000).unref(); + isShuttingDown = true; try { if (runner) { @@ -56,7 +61,8 @@ void (async function start() { runner = new JsTaskRunner(config); runner.on('runner:reached-idle-timeout', () => { - void createSignalHandler('IDLE_TIMEOUT')(); + // Use shorter timeout since we know we don't have any tasks running + void createSignalHandler('IDLE_TIMEOUT', 1)(); }); const { enabled, host, port } = config.baseRunnerConfig.healthcheckServer;