Unable to execute workflow in queue mode

I’m attempting to scale up n8n following the official instruction, I have the following setup locally via docker-compose:

  • n8n (main process)
  • n8n (worker)
  • Redis
  • Postgres

Using a simple example workflow, it is able to execute successfully when triggered manually, and via cronjob trigger when EXECUTIONS_MODE is not set to queue.

However, when EXECUTIONS_MODE=queue is configured, the job executes successfully when triggered manually, but fails to execute when triggered by cronjob with the following log:

2021-09-07T02:40:59.020Z | error    | Problem with execution 7: Cannot read property 'id' of undefined. Aborting. {"file":"WorkflowRunner.js"}
(node:7) UnhandledPromiseRejectionWarning: Error: Cannot read property 'id' of undefined
    at Queue.onFailed (/usr/local/lib/node_modules/n8n/node_modules/bull/lib/job.js:516:18)
    at Queue.emit (events.js:315:20)
    at Queue.EventEmitter.emit (domain.js:467:12)
    at Redis.messageHandler (/usr/local/lib/node_modules/n8n/node_modules/bull/lib/queue.js:444:14)
    at Redis.emit (events.js:315:20)
    at Redis.EventEmitter.emit (domain.js:467:12)
    at DataHandler.handleSubscriberReply (/usr/local/lib/node_modules/n8n/node_modules/ioredis/built/DataHandler.js:80:32)
    at DataHandler.returnReply (/usr/local/lib/node_modules/n8n/node_modules/ioredis/built/DataHandler.js:47:18)
    at JavascriptRedisParser.returnReply (/usr/local/lib/node_modules/n8n/node_modules/ioredis/built/DataHandler.js:21:22)
    at JavascriptRedisParser.execute (/usr/local/lib/node_modules/n8n/node_modules/redis-parser/lib/parser.js:544:14)
    at Socket.<anonymous> (/usr/local/lib/node_modules/n8n/node_modules/ioredis/built/DataHandler.js:25:20)
    at Socket.emit (events.js:315:20)
    at Socket.EventEmitter.emit (domain.js:467:12)
    at addChunk (internal/streams/readable.js:309:12)
    at readableAddChunk (internal/streams/readable.js:284:9)
    at Socket.Readable.push (internal/streams/readable.js:223:10)
    at TCP.onStreamRead (internal/stream_base_commons.js:188:23)
(node:7) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 7)

I suspected the n8n main process’s --tunnel flag could be the cause, but the same issue persists even without the --tunnel flag. Perhaps I miss some configuration on the n8n worker? Thanks for the help in advance!

Here’s some more details on my setup:

Workflow used for testing

docker-compose

version: "3.8"
services:
  n8n:
    container_name: n8n
    image: n8nio/n8n:0.135.2
    command: n8n start --tunnel
    restart: always
    environment:
      # ----- redis ----- #
      QUEUE_BULL_REDIS_HOST: n8n_redis
      QUEUE_BULL_REDIS_PORT: 6379
      # ----- postgres ----- #
      DB_TYPE: postgresdb
      DB_TABLE_PREFIX: n8n
      DB_POSTGRESDB_DATABASE: n8n
      DB_POSTGRESDB_HOST: n8n_postgres
      DB_POSTGRESDB_PORT: 5432
      DB_POSTGRESDB_USER: admin
      DB_POSTGRESDB_PASSWORD: thisisarandompassword
      # ----- logging ----- #
      N8N_LOG_LEVEL: verbose
      # ----- scaling ----- #
      EXECUTIONS_MODE: queue
    ports:
      - 5677:5678
  n8n_worker:
    container_name: n8n_worker
    image: n8nio/n8n:0.135.2
    command: n8n worker
    restart: always
    environment:
      # ----- redis ----- #
      QUEUE_BULL_REDIS_HOST: n8n_redis
      QUEUE_BULL_REDIS_PORT: 6379
      # ----- postgres ----- #
      DB_TYPE: postgresdb
      DB_POSTGRESDB_DATABASE: n8n
      DB_POSTGRESDB_HOST: n8n_postgres
      DB_POSTGRESDB_PORT: 5432
      DB_POSTGRESDB_USER: admin
      DB_POSTGRESDB_PASSWORD: thisisarandompassword
    ports:
      - 5676:5678
  n8n_redis:
    container_name: n8n_redis
    image: redis:6.2.5-alpine
    restart: always
    ports:
      - 6379:6379
  n8n_postgres:
    container_name: n8n_postgres
    image: postgres:9.6.17-alpine
    restart: always
    ports:
      - 5432:5432
    environment:
      POSTGRES_DB: n8n
      POSTGRES_USER: admin
      POSTGRES_PASSWORD: thisisarandompassword
1 Like

Hey @Billyf!

Welcome to the community :sparkling_heart:

You don’t require the --tunnel flag to start n8n. To help you with the issue of using the queue mode, I’ve assigned this to @krynble.

Hello @Billyf

Welcome to our community!

Took me a little while to figure out but I found the issue! In your docker-compose file there is one difference between the main and worker process declarations: table prefix.

Your worker is missing the line DB_TABLE_PREFIX: n8n

This was causing each instance to look to a different set of tables in the database, making them unable to properly work together.

Also I would recommend adding:

    depends_on:
      - "n8n_redis"
      - "n8n_postgres"

To n8n’s main process and

    depends_on:
      - "n8n_redis"
      - "n8n_postgres"
      - "n8n"

To your worker.

Have fun automating!

3 Likes

Hi @krynble!

Yikes what a silly trap I set for myself, you were spot on the problem!
Thanks for your quick response suggestion on depends_on!

Have a great day!

2 Likes