fix(core): Fix shutdown if terminating before hooks are initialized (#8047)

If the app receives termination signal before hooks have been
initialised, the would be objet is undefined error. This PR fixes that.
This commit is contained in:
Tomi Turtiainen 2023-12-18 09:23:10 +02:00 committed by GitHub
parent 2689c37e87
commit 6ae2f5efea
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 5 additions and 5 deletions

View file

@ -26,7 +26,7 @@ import { WorkflowHistoryManager } from '@/workflows/workflowHistory/workflowHist
export abstract class BaseCommand extends Command { export abstract class BaseCommand extends Command {
protected logger = Container.get(Logger); protected logger = Container.get(Logger);
protected externalHooks: IExternalHooksClass; protected externalHooks?: IExternalHooksClass;
protected nodeTypes: NodeTypes; protected nodeTypes: NodeTypes;

View file

@ -101,7 +101,7 @@ export class Start extends BaseCommand {
// Stop with trying to activate workflows that could not be activated // Stop with trying to activate workflows that could not be activated
this.activeWorkflowRunner.removeAllQueuedWorkflowActivations(); this.activeWorkflowRunner.removeAllQueuedWorkflowActivations();
await this.externalHooks.run('n8n.stop', []); await this.externalHooks?.run('n8n.stop', []);
setTimeout(async () => { setTimeout(async () => {
// In case that something goes wrong with shutdown we // In case that something goes wrong with shutdown we

View file

@ -39,7 +39,7 @@ export class Webhook extends BaseCommand {
this.logger.info('\nStopping n8n...'); this.logger.info('\nStopping n8n...');
try { try {
await this.externalHooks.run('n8n.stop', []); await this.externalHooks?.run('n8n.stop', []);
setTimeout(async () => { setTimeout(async () => {
// In case that something goes wrong with shutdown we // In case that something goes wrong with shutdown we

View file

@ -79,7 +79,7 @@ export class Worker extends BaseCommand {
await Worker.jobQueue.pause(true); await Worker.jobQueue.pause(true);
try { try {
await this.externalHooks.run('n8n.stop', []); await this.externalHooks?.run('n8n.stop', []);
const maxStopTime = config.getEnv('queue.bull.gracefulShutdownTimeout') * 1000; const maxStopTime = config.getEnv('queue.bull.gracefulShutdownTimeout') * 1000;
@ -483,7 +483,7 @@ export class Worker extends BaseCommand {
}); });
await new Promise<void>((resolve) => server.listen(port, () => resolve())); await new Promise<void>((resolve) => server.listen(port, () => resolve()));
await this.externalHooks.run('worker.ready'); await this.externalHooks?.run('worker.ready');
this.logger.info(`\nn8n worker health check via, port ${port}`); this.logger.info(`\nn8n worker health check via, port ${port}`);
} }