fix(core): Stop using unbound calls to stopProcess (no-changelog) (#5456)

This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™
2023-02-10 16:34:39 +01:00
committed by GitHub
parent d266401ed8
commit 9a331ec7b6
5 changed files with 11 additions and 26 deletions

View File

@@ -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);
}
}