mirror of
https://github.com/n8n-io/n8n.git
synced 2024-09-20 14:57:31 -07: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 { ExitError } from '@oclif/errors';
|
||||
import type { INodeTypes } from 'n8n-workflow';
|
||||
import { LoggerProxy, ErrorReporterProxy as ErrorReporter, sleep } from 'n8n-workflow';
|
||||
import type { IUserSettings } from 'n8n-core';
|
||||
|
@ -35,8 +36,8 @@ export abstract class BaseCommand extends Command {
|
|||
async init(): Promise<void> {
|
||||
await initErrorHandling();
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||
this.stopProcess = this.stopProcess.bind(this);
|
||||
process.once('SIGTERM', async () => this.stopProcess());
|
||||
process.once('SIGINT', async () => this.stopProcess());
|
||||
|
||||
// Make sure the settings exist
|
||||
this.userSettings = await UserSettings.prepareUserSettings();
|
||||
|
@ -88,7 +89,11 @@ export abstract class BaseCommand extends Command {
|
|||
|
||||
async finally(error: Error | undefined) {
|
||||
if (inTest || this.id === 'start') return;
|
||||
if (Db.isInitialized) await Db.connection.destroy();
|
||||
this.exit(error ? 1 : 0);
|
||||
if (Db.isInitialized) {
|
||||
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.
|
||||
* @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) {
|
||||
process.exit(0);
|
||||
}
|
||||
|
@ -168,11 +168,6 @@ export class ExecuteBatch extends BaseCommand {
|
|||
}
|
||||
|
||||
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
|
||||
const { flags } = this.parse(ExecuteBatch);
|
||||
|
||||
|
@ -318,7 +313,7 @@ export class ExecuteBatch extends BaseCommand {
|
|||
console.log(this.formatJsonOutput(results));
|
||||
}
|
||||
|
||||
await ExecuteBatch.stopProcess(true);
|
||||
await this.stopProcess(true);
|
||||
|
||||
if (results.summary.failedExecutions > 0) {
|
||||
this.exit(1);
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
/* 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-member-access */
|
||||
import path from 'path';
|
||||
|
@ -199,10 +198,6 @@ export class Start extends BaseCommand {
|
|||
}
|
||||
|
||||
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 super.init();
|
||||
this.logger.info('Initializing n8n process');
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
/* eslint-disable @typescript-eslint/unbound-method */
|
||||
import { flags } from '@oclif/command';
|
||||
import { LoggerProxy, sleep } from 'n8n-workflow';
|
||||
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.');
|
||||
}
|
||||
|
||||
// Make sure that n8n shuts down gracefully if possible
|
||||
process.once('SIGTERM', this.stopProcess);
|
||||
process.once('SIGINT', this.stopProcess);
|
||||
|
||||
await this.initCrashJournal();
|
||||
await super.init();
|
||||
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
/* eslint-disable @typescript-eslint/unbound-method */
|
||||
import express from 'express';
|
||||
import http from 'http';
|
||||
import type PCancelable from 'p-cancelable';
|
||||
|
@ -219,10 +218,6 @@ export class Worker extends BaseCommand {
|
|||
}
|
||||
|
||||
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 super.init();
|
||||
this.logger.debug('Starting n8n worker...');
|
||||
|
|
Loading…
Reference in a new issue