fix(core): Ensure cancellation interrupts runner tasks in worker (#19864)

This commit is contained in:
Iván Ovejero 2025-09-25 11:24:03 +02:00 committed by GitHub
parent 22d5459a72
commit fac005b165
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 1 deletions

View File

@ -72,6 +72,7 @@ describe('JobProcessor', () => {
mock(),
mock(),
executionsConfig,
mock(),
);
const result = await jobProcessor.processJob(mock<Job>());
@ -102,6 +103,7 @@ describe('JobProcessor', () => {
mock(),
manualExecutionService,
executionsConfig,
mock(),
);
await jobProcessor.processJob(mock<Job>());
@ -141,6 +143,7 @@ describe('JobProcessor', () => {
mock(),
manualExecutionService,
executionsConfig,
mock(),
);
const executionId = 'execution-id';
@ -204,6 +207,7 @@ describe('JobProcessor', () => {
mock(),
manualExecutionService,
executionsConfig,
mock(),
);
await jobProcessor.processJob(mock<Job>());

View File

@ -14,6 +14,7 @@ import type {
import { BINARY_ENCODING, Workflow, UnexpectedError } from 'n8n-workflow';
import type PCancelable from 'p-cancelable';
import { EventService } from '@/events/event.service';
import { getLifecycleHooksForScalingWorker } from '@/execution-lifecycle/execution-lifecycle-hooks';
import { ManualExecutionService } from '@/manual-execution.service';
import { NodeTypes } from '@/node-types';
@ -44,6 +45,7 @@ export class JobProcessor {
private readonly instanceSettings: InstanceSettings,
private readonly manualExecutionService: ManualExecutionService,
private readonly executionsConfig: ExecutionsConfig,
private readonly eventService: EventService,
) {
this.logger = this.logger.scoped('scaling');
}
@ -269,7 +271,13 @@ export class JobProcessor {
}
stopJob(jobId: JobId) {
this.runningJobs[jobId]?.run.cancel();
const runningJob = this.runningJobs[jobId];
if (!runningJob) return;
const executionId = runningJob.executionId;
this.eventService.emit('execution-cancelled', { executionId });
runningJob.run.cancel();
delete this.runningJobs[jobId];
}