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;