Skip to content

Commit

Permalink
fix(core): Make sure task runner exits (#12123)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomi committed Dec 10, 2024
1 parent 6715662 commit 996c9e9
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/@n8n/task-runner/src/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,19 @@ 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;
}

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) {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 996c9e9

Please # to comment.