-
Notifications
You must be signed in to change notification settings - Fork 29.7k
fix(core): Ensure queue is ready when enqueueing #16098
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cubic found 1 issue across 3 files. Review it in cubic.dev
React with 👍 or 👎 to teach cubic. Tag @cubic-dev-ai
to give specific feedback.
Codecov ReportAttention: Patch coverage is
📢 Thoughts on this report? Let us know! |
@@ -55,6 +55,8 @@ export class ScalingService { | |||
// #region Lifecycle | |||
|
|||
async setupQueue() { | |||
if (this.queue) return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not 100% but I think checking the queue here could lead to race condition, because the code could enter this method twice while we wait in line 60 or 61 for the dynamic imports, in which case the queue value would be overwritten by the later call. If we move this check after the await statements in line 60 and 61 the assignment of the queue variable will only happen once, because there no real threads.
@ivov I frequently encounter this situation. To reproduce it, concurrent task execution is needed, and errors occur frequently under such conditions. |
Summary
There are edge cases where
WorkflowRunner
attempts to enqueue before the queue is ready. For legacy reasonsScalingService
is being dynamically imported in multiple spots, so this is a risk and appears to be related to workers enqueuing executions of error-handling workflows, but I have not been able to reproduce the edge case locally.This PR ensures the queue is ready when enqueuing. The root solution would be to modularize scaling mode and remove its multiple dynamic imports, and so that all code paths relying on scaling mode are guaranteed that scaling mode init is complete. Adi made an attempt at #11278 but was not satisfied.
Let's fix this now for the time being and work towards modularizing scaling mode when time allows.
Related Linear tickets, Github issues, and Community forum posts
https://linear.app/n8n/issue/CAT-784
Fix #15233
Review / Merge checklist
release/backport
(if the PR is an urgent fix that needs to be backported)