Skip to content

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

ivov
Copy link
Contributor

@ivov ivov commented Jun 6, 2025

Summary

There are edge cases where WorkflowRunner attempts to enqueue before the queue is ready. For legacy reasons ScalingService 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

  • PR title and summary are descriptive. (conventions)
  • Docs updated or follow-up ticket created.
  • Tests included.
  • PR Labeled with release/backport (if the PR is an urgent fix that needs to be backported)

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a 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.

@ivov ivov requested a review from afitzek June 6, 2025 14:13
Copy link

codecov bot commented Jun 6, 2025

Codecov Report

Attention: Patch coverage is 50.00000% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
packages/cli/src/scaling/scaling.service.ts 0.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@@ -55,6 +55,8 @@ export class ScalingService {
// #region Lifecycle

async setupQueue() {
if (this.queue) return;
Copy link
Contributor

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.

@n8n-assistant n8n-assistant bot added core Enhancement outside /nodes-base and /editor-ui n8n team Authored by the n8n team labels Jun 6, 2025
@checkblue
Copy link

@ivov I frequently encounter this situation. To reproduce it, concurrent task execution is needed, and errors occur frequently under such conditions.

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[bug] Error workflow fails with "Cannot read properties of undefined (reading 'add')" in Queue Mode
3 participants