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
  • Loading branch information
tomi committed Dec 15, 2023
1 parent 989888d commit 6203496
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 6203496

Please sign in to comment.