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 execution cancellation in scaling mode #9841

Merged
merged 4 commits into from
Jun 28, 2024

Conversation

ivov
Copy link
Contributor

@ivov ivov commented Jun 24, 2024

While working on #9835 I noticed that execution cancellation is broken in queue mode - cancelling leads to an error status instead of canceled and does not remove the job from the queue so it goes through anyway.

This PR fixes this issue, refactors cancellation out of WaitTracker, and adds tests.

https://linear.app/n8n/issue/PAY-1709

@n8n-assistant n8n-assistant bot added core Enhancement outside /nodes-base and /editor-ui n8n team Authored by the n8n team labels Jun 24, 2024
}

// queue mode
return await this.executionRepository.stopDuringRun(execution);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be part of the responsibility of activeExecutions rather than being here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I like about the flow right now is that it gives a clear overview of all the calls being made to stop the execution, with everything in a single spot:

ExecutionService.stopInRegularMode
	ConcurrencyControl.remove
	ExecutionRepository.stopBeforeRun
	// or 
	ActiveExecutions.stopExecution
	WaitTracker.stopExecution
	ExecutionRepository.stopDuringRun

ExecutionService.stopInScalingMode
	ExecutionService.stopInRegularMode
	// or
	WaitTracker.stopExecution
	this.queue.stopJob
	ExecutionRepository.stopDuringRun

If we moved ExecutionRepository.stopDuringRun

  • this would require more navigation to see the full picture and
  • ExecutionRepository.stopBeforeRun would still remain in ExecutionService unless we also move that to ConcurrencyControl.remove
ExecutionService.stopInRegularMode
	ConcurrencyControl.remove
	// or 
	ActiveExecutions.stopExecution
	WaitTracker.stopExecution

ExecutionService.stopInScalingMode
	ExecutionService.stopInRegularMode
	// or
	WaitTracker.stopExecution
	this.queue.stopJob

The root issue in my eyes is that there is no clear distinction between what ExecutionService and what ActiveExecutions should be responsible for. Until we differentiate them better, I'd find the former flow easier to debug.

return await this.waitTracker.stopExecution(execution.id);
} catch {
// @TODO: Why are we swallowing this error in queue mode?
private async stopInScalingMode(execution: IExecutionResponse) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if it's a manual execution? In this case it would be viewable in activeExecutions and can be cancelled from there.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see dcb93be

@netroy netroy self-requested a review June 27, 2024 11:33
Copy link
Member

@netroy netroy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What what I can understand, LGTM.

Copy link

cypress bot commented Jun 27, 2024

3 flaky tests on run #5720 ↗︎

0 398 0 0 Flakiness 3

Details:

🌳 master 🖥️ browsers:node18.12.0-chrome107 🤖 PR User 🗃️ e2e/*
Project: n8n Commit: e613de28ca
Status: Passed Duration: 05:12 💡
Started: Jul 1, 2024 3:11 AM Ended: Jul 1, 2024 3:16 AM
Flakiness  5-ndv.cy.ts • 2 flaky tests

View Output Video

Test Artifacts
NDV > should not retrieve remote options when required params throw errors Screenshots Video
NDV > Stop listening for trigger event from NDV Screenshots Video
Flakiness  24-ndv-paired-item.cy.ts • 1 flaky test

View Output Video

Test Artifacts
NDV > resolves expression with default item when input node is not parent, while still pairing items Test Replay Screenshots Video

Review all test suite changes for PR #9841 ↗︎

Copy link
Contributor

✅ All Cypress E2E specs passed

@ivov ivov merged commit e613de2 into master Jun 28, 2024
38 checks passed
@ivov ivov deleted the fix-execution-cancellation-in-scaling-mode branch June 28, 2024 18:05
@github-actions github-actions bot mentioned this pull request Jul 3, 2024
@janober
Copy link
Member

janober commented Jul 3, 2024

Got released with n8n@1.49.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Enhancement outside /nodes-base and /editor-ui n8n team Authored by the n8n team Released
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants