Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading