-
Notifications
You must be signed in to change notification settings - Fork 8.9k
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): Ensure executions cannot resume if already running #10014
Conversation
4 flaky tests on run #5880 ↗︎
Details:
5-ndv.cy.ts • 2 flaky tests
10-undo-redo.cy.ts • 1 flaky test
24-ndv-paired-item.cy.ts • 1 flaky test
Review all test suite changes for PR #10014 ↗︎ |
✅ All Cypress E2E specs passed |
This is not fixing the race condition. It will only make it less likely, but the race condition is still there. The race condition comes from the time between reading the execution from the db and update the status in the db: Read: n8n/packages/cli/src/WaitingWebhooks.ts Lines 51 to 54 in d651be4
Write: n8n/packages/cli/src/WorkflowRunner.ts Line 257 in d651be4
On my machines in main mode that's ca. 35ms. This needs to be effectively 0 for the race condition to be gone. You can still reproduce this if you do This is an improvement over what it was before: What I had in mind as a fix was doing pessimistic locking on the application layer, e.g. updating the status only if it was waiting and then only continue if the update worked: // ...
const result = await this.executionRepository.update(
{ id: executionId, status: 'waiting' },
{ status: 'running' },
);
if (result.affected === 0) {
throw new ConflictError(`The execution "${executionId} is running already.`);
}
const execution = await this.executionRepository.findSingleExecution(executionId, {
includeData: true,
unflattenData: true,
});
// ... With that in place we get this: The problem is that this may bypass the execution recovery, or have side effects with it that I can't foresee. |
Got released with |
https://linear.app/n8n/issue/PAY-1554