mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
fix(core): Handle multiple termination signals correctly (#8046)
Prevent possible multiple termination signals initiating the shutdown process multiple times.
This commit is contained in:
parent
e69707efd4
commit
67bd8ad698
|
@ -38,12 +38,14 @@ export abstract class BaseCommand extends Command {
|
||||||
|
|
||||||
protected server?: AbstractServer;
|
protected server?: AbstractServer;
|
||||||
|
|
||||||
|
protected isShuttingDown = false;
|
||||||
|
|
||||||
async init(): Promise<void> {
|
async init(): Promise<void> {
|
||||||
await initErrorHandling();
|
await initErrorHandling();
|
||||||
initExpressionEvaluator();
|
initExpressionEvaluator();
|
||||||
|
|
||||||
process.once('SIGTERM', async () => this.stopProcess());
|
process.once('SIGTERM', this.onTerminationSignal('SIGTERM'));
|
||||||
process.once('SIGINT', async () => this.stopProcess());
|
process.once('SIGINT', this.onTerminationSignal('SIGINT'));
|
||||||
|
|
||||||
// Make sure the settings exist
|
// Make sure the settings exist
|
||||||
this.instanceSettings = Container.get(InstanceSettings);
|
this.instanceSettings = Container.get(InstanceSettings);
|
||||||
|
@ -299,4 +301,17 @@ export abstract class BaseCommand extends Command {
|
||||||
const exitCode = error instanceof ExitError ? error.oclif.exit : error ? 1 : 0;
|
const exitCode = error instanceof ExitError ? error.oclif.exit : error ? 1 : 0;
|
||||||
this.exit(exitCode);
|
this.exit(exitCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private onTerminationSignal(signal: string) {
|
||||||
|
return async () => {
|
||||||
|
if (this.isShuttingDown) {
|
||||||
|
this.logger.info(`Received ${signal}. Already shutting down...`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.logger.info(`Received ${signal}. Shutting down...`);
|
||||||
|
this.isShuttingDown = true;
|
||||||
|
await this.stopProcess();
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue