mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-31 15:37:26 -08:00
fix(core): Make sure task runner exits (#12123)
This commit is contained in:
parent
a50969b244
commit
c5effca7d4
|
@ -11,7 +11,7 @@ let runner: JsTaskRunner | undefined;
|
||||||
let isShuttingDown = false;
|
let isShuttingDown = false;
|
||||||
let errorReporter: ErrorReporter | undefined;
|
let errorReporter: ErrorReporter | undefined;
|
||||||
|
|
||||||
function createSignalHandler(signal: string) {
|
function createSignalHandler(signal: string, timeoutInS = 10) {
|
||||||
return async function onSignal() {
|
return async function onSignal() {
|
||||||
if (isShuttingDown) {
|
if (isShuttingDown) {
|
||||||
return;
|
return;
|
||||||
|
@ -19,6 +19,11 @@ function createSignalHandler(signal: string) {
|
||||||
|
|
||||||
console.log(`Received ${signal} signal, shutting down...`);
|
console.log(`Received ${signal} signal, shutting down...`);
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
console.error('Shutdown timeout reached, forcing shutdown...');
|
||||||
|
process.exit(1);
|
||||||
|
}, timeoutInS * 1000).unref();
|
||||||
|
|
||||||
isShuttingDown = true;
|
isShuttingDown = true;
|
||||||
try {
|
try {
|
||||||
if (runner) {
|
if (runner) {
|
||||||
|
@ -56,7 +61,8 @@ void (async function start() {
|
||||||
|
|
||||||
runner = new JsTaskRunner(config);
|
runner = new JsTaskRunner(config);
|
||||||
runner.on('runner:reached-idle-timeout', () => {
|
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;
|
const { enabled, host, port } = config.baseRunnerConfig.healthcheckServer;
|
||||||
|
|
Loading…
Reference in a new issue