Skip to content

Commit

Permalink
fix(core): Fix shutdown if terminating before hooks are initialized (#…
Browse files Browse the repository at this point in the history
…8047)

If the app receives termination signal before hooks have been
initialised, the would be objet is undefined error. This PR fixes that.
  • Loading branch information
tomi authored Dec 18, 2023
1 parent 2689c37 commit 6ae2f5e
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/cli/src/commands/BaseCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { WorkflowHistoryManager } from '@/workflows/workflowHistory/workflowHist
export abstract class BaseCommand extends Command {
protected logger = Container.get(Logger);

protected externalHooks: IExternalHooksClass;
protected externalHooks?: IExternalHooksClass;

protected nodeTypes: NodeTypes;

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export class Start extends BaseCommand {
// Stop with trying to activate workflows that could not be activated
this.activeWorkflowRunner.removeAllQueuedWorkflowActivations();

await this.externalHooks.run('n8n.stop', []);
await this.externalHooks?.run('n8n.stop', []);

setTimeout(async () => {
// In case that something goes wrong with shutdown we
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/webhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class Webhook extends BaseCommand {
this.logger.info('\nStopping n8n...');

try {
await this.externalHooks.run('n8n.stop', []);
await this.externalHooks?.run('n8n.stop', []);

setTimeout(async () => {
// In case that something goes wrong with shutdown we
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/commands/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export class Worker extends BaseCommand {
await Worker.jobQueue.pause(true);

try {
await this.externalHooks.run('n8n.stop', []);
await this.externalHooks?.run('n8n.stop', []);

const maxStopTime = config.getEnv('queue.bull.gracefulShutdownTimeout') * 1000;

Expand Down Expand Up @@ -483,7 +483,7 @@ export class Worker extends BaseCommand {
});

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

Expand Down

0 comments on commit 6ae2f5e

Please sign in to comment.