mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
fix(core): Stop using unbound calls to stopProcess
(no-changelog) (#5456)
This commit is contained in:
parent
d266401ed8
commit
9a331ec7b6
|
@ -1,4 +1,5 @@
|
||||||
import { Command } from '@oclif/command';
|
import { Command } from '@oclif/command';
|
||||||
|
import { ExitError } from '@oclif/errors';
|
||||||
import type { INodeTypes } from 'n8n-workflow';
|
import type { INodeTypes } from 'n8n-workflow';
|
||||||
import { LoggerProxy, ErrorReporterProxy as ErrorReporter, sleep } from 'n8n-workflow';
|
import { LoggerProxy, ErrorReporterProxy as ErrorReporter, sleep } from 'n8n-workflow';
|
||||||
import type { IUserSettings } from 'n8n-core';
|
import type { IUserSettings } from 'n8n-core';
|
||||||
|
@ -35,8 +36,8 @@ export abstract class BaseCommand extends Command {
|
||||||
async init(): Promise<void> {
|
async init(): Promise<void> {
|
||||||
await initErrorHandling();
|
await initErrorHandling();
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
process.once('SIGTERM', async () => this.stopProcess());
|
||||||
this.stopProcess = this.stopProcess.bind(this);
|
process.once('SIGINT', async () => this.stopProcess());
|
||||||
|
|
||||||
// Make sure the settings exist
|
// Make sure the settings exist
|
||||||
this.userSettings = await UserSettings.prepareUserSettings();
|
this.userSettings = await UserSettings.prepareUserSettings();
|
||||||
|
@ -88,7 +89,11 @@ export abstract class BaseCommand extends Command {
|
||||||
|
|
||||||
async finally(error: Error | undefined) {
|
async finally(error: Error | undefined) {
|
||||||
if (inTest || this.id === 'start') return;
|
if (inTest || this.id === 'start') return;
|
||||||
if (Db.isInitialized) await Db.connection.destroy();
|
if (Db.isInitialized) {
|
||||||
this.exit(error ? 1 : 0);
|
await sleep(100); // give any in-flight query some time to finish
|
||||||
|
await Db.connection.destroy();
|
||||||
|
}
|
||||||
|
const exitCode = error instanceof ExitError ? error.oclif.exit : error ? 1 : 0;
|
||||||
|
this.exit(exitCode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,7 +95,7 @@ export class ExecuteBatch extends BaseCommand {
|
||||||
* Gracefully handles exit.
|
* Gracefully handles exit.
|
||||||
* @param {boolean} skipExit Whether to skip exit or number according to received signal
|
* @param {boolean} skipExit Whether to skip exit or number according to received signal
|
||||||
*/
|
*/
|
||||||
static async stopProcess(skipExit: boolean | number = false) {
|
async stopProcess(skipExit: boolean | number = false) {
|
||||||
if (ExecuteBatch.cancelled) {
|
if (ExecuteBatch.cancelled) {
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
}
|
||||||
|
@ -168,11 +168,6 @@ export class ExecuteBatch extends BaseCommand {
|
||||||
}
|
}
|
||||||
|
|
||||||
async run() {
|
async run() {
|
||||||
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
||||||
process.once('SIGTERM', ExecuteBatch.stopProcess);
|
|
||||||
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
||||||
process.once('SIGINT', ExecuteBatch.stopProcess);
|
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-shadow
|
// eslint-disable-next-line @typescript-eslint/no-shadow
|
||||||
const { flags } = this.parse(ExecuteBatch);
|
const { flags } = this.parse(ExecuteBatch);
|
||||||
|
|
||||||
|
@ -318,7 +313,7 @@ export class ExecuteBatch extends BaseCommand {
|
||||||
console.log(this.formatJsonOutput(results));
|
console.log(this.formatJsonOutput(results));
|
||||||
}
|
}
|
||||||
|
|
||||||
await ExecuteBatch.stopProcess(true);
|
await this.stopProcess(true);
|
||||||
|
|
||||||
if (results.summary.failedExecutions > 0) {
|
if (results.summary.failedExecutions > 0) {
|
||||||
this.exit(1);
|
this.exit(1);
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
/* eslint-disable @typescript-eslint/await-thenable */
|
/* eslint-disable @typescript-eslint/await-thenable */
|
||||||
/* eslint-disable @typescript-eslint/unbound-method */
|
|
||||||
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
||||||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
@ -199,10 +198,6 @@ export class Start extends BaseCommand {
|
||||||
}
|
}
|
||||||
|
|
||||||
async init() {
|
async init() {
|
||||||
// Make sure that n8n shuts down gracefully if possible
|
|
||||||
process.once('SIGTERM', this.stopProcess);
|
|
||||||
process.once('SIGINT', this.stopProcess);
|
|
||||||
|
|
||||||
await this.initCrashJournal();
|
await this.initCrashJournal();
|
||||||
await super.init();
|
await super.init();
|
||||||
this.logger.info('Initializing n8n process');
|
this.logger.info('Initializing n8n process');
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
/* eslint-disable @typescript-eslint/unbound-method */
|
|
||||||
import { flags } from '@oclif/command';
|
import { flags } from '@oclif/command';
|
||||||
import { LoggerProxy, sleep } from 'n8n-workflow';
|
import { LoggerProxy, sleep } from 'n8n-workflow';
|
||||||
import config from '@/config';
|
import config from '@/config';
|
||||||
|
@ -71,10 +70,6 @@ export class Webhook extends BaseCommand {
|
||||||
this.error('Webhook processes can only run with execution mode as queue.');
|
this.error('Webhook processes can only run with execution mode as queue.');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure that n8n shuts down gracefully if possible
|
|
||||||
process.once('SIGTERM', this.stopProcess);
|
|
||||||
process.once('SIGINT', this.stopProcess);
|
|
||||||
|
|
||||||
await this.initCrashJournal();
|
await this.initCrashJournal();
|
||||||
await super.init();
|
await super.init();
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
/* eslint-disable @typescript-eslint/unbound-method */
|
|
||||||
import express from 'express';
|
import express from 'express';
|
||||||
import http from 'http';
|
import http from 'http';
|
||||||
import type PCancelable from 'p-cancelable';
|
import type PCancelable from 'p-cancelable';
|
||||||
|
@ -219,10 +218,6 @@ export class Worker extends BaseCommand {
|
||||||
}
|
}
|
||||||
|
|
||||||
async init() {
|
async init() {
|
||||||
// Make sure that n8n shuts down gracefully if possible
|
|
||||||
process.once('SIGTERM', this.stopProcess);
|
|
||||||
process.once('SIGINT', this.stopProcess);
|
|
||||||
|
|
||||||
await this.initCrashJournal();
|
await this.initCrashJournal();
|
||||||
await super.init();
|
await super.init();
|
||||||
this.logger.debug('Starting n8n worker...');
|
this.logger.debug('Starting n8n worker...');
|
||||||
|
|
Loading…
Reference in a new issue