504 Gateway Timeout errors at random

Bug Description

The frontend of my locally hosted n8n instance becomes unresponsive resulting in a 504 Gateway Timeout error. While it is unresponsive not only the frontend fails to respond, but the workflows are also on halt. I am doing my best to describe my setup here:

This is my docke-compose file:

networks:
  monitoring:
    name: monitoring
    external: true

volumes:
  n8n_data:
    driver: local
  postgres_data:
    driver: local

services:
  n8n:
    image: docker.n8n.io/n8nio/n8n:latest
    container_name: n8n
    restart: always
    ports:
      - 5678:5678
    environment:
      - EXECUTIONS_TIMEOUT=$EXECUTIONS_TIMEOUT
      - N8N_HOST=$N8N_HOST
      - N8N_PROTOCOL=$N8N_PROTOCOL
      - WEBHOOK_URL=$WEBHOOK_URL
      - DOMAIN_NAME=$DOMAIN_NAME
      - SUBDOMAIN=$SUBDOMAIN
      - N8N_SECURE_COOKIE=$N8N_SECURE_COOKIE
      - NODE_ENV=$NODE_ENV
      - GENERIC_TIMEZONE=$GENERIC_TIMEZONE
      - DB_TYPE=$DB_TYPE
      - DB_POSTGRESDB_HOST=$DB_POSTGRESDB_HOST
      - DB_POSTGRESDB_PORT=$DB_POSTGRESDB_PORT
      - DB_POSTGRESDB_DATABASE=$POSTGRES_DB
      - DB_POSTGRESDB_USER=$POSTGRES_USER
      - DB_POSTGRESDB_PASSWORD=$POSTGRES_PASSWORD
    networks:
      - monitoring
    depends_on:
      postgres:
        condition: service_healthy
    links:
      - postgres
    volumes:
      - n8n_data:/home/node/.n8n

  postgres:
    image: postgres:16
    container_name: n8n-postgres
    restart: always
    environment:
      - POSTGRES_USER=$POSTGRES_USER
      - POSTGRES_PASSWORD=$POSTGRES_PASSWORD
      - POSTGRES_DB=$POSTGRES_DB
      - POSTGRES_NON_ROOT_USER=$POSTGRES_NON_ROOT_USER
      - POSTGRES_NON_ROOT_PASSWORD=$POSTGRES_NON_ROOT_PASSWORD
    volumes:
      - postgres_data:/var/lib/postgresql/data
      - ./init-data.sh:/docker-entrypoint-initdb.d/init-data.sh
    networks:
      - monitoring
    healthcheck:
      test: ['CMD-SHELL', 'pg_isready -h localhost -U ${POSTGRES_USER} -d ${POSTGRES_DB}']
      interval: 5s
      timeout: 5s
      retries: 10

I am running the docker host on a vm inside Proxmox. My flows are the following:

Image

Image

Image

The logs of the n8n docker instance are the following:

node execution output incorrect data

Error: node execution output incorrect data

    at WorkflowExecute.runNode (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-core@[email protected][email protected][email protected]_/node_modules/n8n-core/src/execution-engine/workflow-execute.ts:1219:6)

    at processTicksAndRejections (node:internal/process/task_queues:105:5)

    at /usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-core@[email protected][email protected][email protected]_/node_modules/n8n-core/src/execution-engine/workflow-execute.ts:1581:27

    at /usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-core@[email protected][email protected][email protected]_/node_modules/n8n-core/src/execution-engine/workflow-execute.ts:2157:11

node execution output incorrect data

Error: node execution output incorrect data

    at WorkflowExecute.runNode (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-core@[email protected][email protected][email protected]_/node_modules/n8n-core/src/execution-engine/workflow-execute.ts:1219:6)

    at processTicksAndRejections (node:internal/process/task_queues:105:5)

    at /usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-core@[email protected][email protected][email protected]_/node_modules/n8n-core/src/execution-engine/workflow-execute.ts:1581:27

    at /usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-core@[email protected][email protected][email protected]_/node_modules/n8n-core/src/execution-engine/workflow-execute.ts:2157:11

node execution output incorrect data

Error: node execution output incorrect data

    at WorkflowExecute.runNode (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-core@[email protected][email protected][email protected]_/node_modules/n8n-core/src/execution-engine/workflow-execute.ts:1219:6)

    at processTicksAndRejections (node:internal/process/task_queues:105:5)

    at /usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-core@[email protected][email protected][email protected]_/node_modules/n8n-core/src/execution-engine/workflow-execute.ts:1581:27

    at /usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-core@[email protected][email protected][email protected]_/node_modules/n8n-core/src/execution-engine/workflow-execute.ts:2157:11

node execution output incorrect data

Error: node execution output incorrect data

    at WorkflowExecute.runNode (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-core@[email protected][email protected][email protected]_/node_modules/n8n-core/src/execution-engine/workflow-execute.ts:1219:6)

    at processTicksAndRejections (node:internal/process/task_queues:105:5)

    at /usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-core@[email protected][email protected][email protected]_/node_modules/n8n-core/src/execution-engine/workflow-execute.ts:1581:27

    at /usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-core@[email protected][email protected][email protected]_/node_modules/n8n-core/src/execution-engine/workflow-execute.ts:2157:11

There was a problem running hook "workflowExecuteAfter" Error: timeout exceeded when trying to connect

    at /usr/local/lib/node_modules/n8n/node_modules/.pnpm/[email protected][email protected]/node_modules/pg-pool/index.js:45:11

    at PostgresDriver.obtainMasterConnection (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/@[email protected]_@[email protected][email protected][email protected]_@aws-sdk+creden_5acd9760022463ab007747f48f178726/node_modules/src/driver/postgres/PostgresDriver.ts:1175:28)

    at PostgresQueryRunner.query (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/@[email protected]_@[email protected][email protected][email protected]_@aws-sdk+creden_5acd9760022463ab007747f48f178726/node_modules/src/driver/postgres/PostgresQueryRunner.ts:248:36)

    at PostgresQueryRunner.startTransaction (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/@[email protected]_@[email protected][email protected][email protected]_@aws-sdk+creden_5acd9760022463ab007747f48f178726/node_modules/src/driver/postgres/PostgresQueryRunner.ts:178:13)

    at EntityManager.transaction (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/@[email protected]_@[email protected][email protected][email protected]_@aws-sdk+creden_5acd9760022463ab007747f48f178726/node_modules/src/entity-manager/EntityManager.ts:153:13)

    at ExecutionRepository.updateExistingExecution (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/@n8n+db@file+packages+@n8n+db_@[email protected][email protected][email protected]_@aws-sdk_f7bd9984f5e38971ca100f511ef3ee0b/node_modules/@n8n/db/src/repositories/execution.repository.ts:428:3)

    at updateExistingExecution (/usr/local/lib/node_modules/n8n/src/execution-lifecycle/shared/shared-hook-functions.ts:90:2)

    at ExecutionLifecycleHooks.<anonymous> (/usr/local/lib/node_modules/n8n/src/execution-lifecycle/execution-lifecycle-hooks.ts:364:4)

    at ExecutionLifecycleHooks.runHook (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-core@[email protected][email protected][email protected]_/node_modules/n8n-core/src/execution-engine/execution-lifecycle-hooks.ts:120:4)

    at /usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-core@[email protected][email protected][email protected]_/node_modules/n8n-core/src/execution-engine/workflow-execute.ts:2135:6

timeout exceeded when trying to connect

timeout exceeded when trying to connect

timeout exceeded when trying to connect

timeout exceeded when trying to connect

timeout exceeded when trying to connect

timeout exceeded when trying to connect

timeout exceeded when trying to connect

timeout exceeded when trying to connect

timeout exceeded when trying to connect

timeout exceeded when trying to connect

timeout exceeded when trying to connect

timeout exceeded when trying to connect

timeout exceeded when trying to connect

timeout exceeded when trying to connect

timeout exceeded when trying to connect

timeout exceeded when trying to connect

timeout exceeded when trying to connect

timeout exceeded when trying to connect

timeout exceeded when trying to connect

timeout exceeded when trying to connect

timeout exceeded when trying to connect

timeout exceeded when trying to connect

There was a problem in 'Gmail Trigger Kontowecker' node in workflow 'NKMkXNGNCxmIba6D': 'undefined'

timeout exceeded when trying to connect

timeout exceeded when trying to connect

timeout exceeded when trying to connect

node execution output incorrect data

Error: node execution output incorrect data

    at WorkflowExecute.runNode (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-core@[email protected][email protected][email protected]_/node_modules/n8n-core/src/execution-engine/workflow-execute.ts:1219:6)

    at processTicksAndRejections (node:internal/process/task_queues:105:5)

    at /usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-core@[email protected][email protected][email protected]_/node_modules/n8n-core/src/execution-engine/workflow-execute.ts:1581:27

    at /usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-core@[email protected][email protected][email protected]_/node_modules/n8n-core/src/execution-engine/workflow-execute.ts:2157:11

timeout exceeded when trying to connect

timeout exceeded when trying to connect

timeout exceeded when trying to connect

timeout exceeded when trying to connect

timeout exceeded when trying to connect

timeout exceeded when trying to connect

timeout exceeded when trying to connect

timeout exceeded when trying to connect

timeout exceeded when trying to connect

timeout exceeded when trying to connect

timeout exceeded when trying to connect

timeout exceeded when trying to connect

timeout exceeded when trying to connect

timeout exceeded when trying to connect

timeout exceeded when trying to connect

timeout exceeded when trying to connect

timeout exceeded when trying to connect

timeout exceeded when trying to connect

timeout exceeded when trying to connect

error Error: timeout exceeded when trying to connect

    at /usr/local/lib/node_modules/n8n/node_modules/.pnpm/[email protected][email protected]/node_modules/pg-pool/index.js:45:11

    at PostgresDriver.obtainMasterConnection (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/@[email protected]_@[email protected][email protected][email protected]_@aws-sdk+creden_5acd9760022463ab007747f48f178726/node_modules/src/driver/postgres/PostgresDriver.ts:1175:28)

    at PostgresQueryRunner.query (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/@[email protected]_@[email protected][email protected][email protected]_@aws-sdk+creden_5acd9760022463ab007747f48f178726/node_modules/src/driver/postgres/PostgresQueryRunner.ts:248:36)

    at DataSource.query (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/@[email protected]_@[email protected][email protected][email protected]_@aws-sdk+creden_5acd9760022463ab007747f48f178726/node_modules/src/data-source/DataSource.ts:539:20)

    at WorkflowStatisticsRepository.upsertWorkflowStatistics (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/@n8n+db@file+packages+@n8n+db_@[email protected][email protected][email protected]_@aws-sdk_f7bd9984f5e38971ca100f511ef3ee0b/node_modules/@n8n/db/src/repositories/workflow-statistics.repository.ts:84:26)

    at WorkflowStatisticsService.workflowExecutionCompleted (/usr/local/lib/node_modules/n8n/src/services/workflow-statistics.service.ts:108:25)

    at WorkflowStatisticsService.<anonymous> (/usr/local/lib/node_modules/n8n/src/services/workflow-statistics.service.ts:83:5)

timeout exceeded when trying to connect

timeout exceeded when trying to connect

timeout exceeded when trying to connect

At the moment I do not have any suspicious logs inside the postgres container, but I will still post them:

PostgreSQL Database directory appears to contain a database; Skipping initialization

2025-07-27 06:55:56.401 UTC [1] LOG:  starting PostgreSQL 16.9 (Debian 16.9-1.pgdg120+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit

2025-07-27 06:55:56.401 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432

2025-07-27 06:55:56.401 UTC [1] LOG:  listening on IPv6 address "::", port 5432

2025-07-27 06:55:56.404 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"

2025-07-27 06:55:56.409 UTC [29] LOG:  database system was shut down at 2025-07-27 06:55:26 UTC

2025-07-27 06:55:56.415 UTC [1] LOG:  database system is ready to accept connections

2025-07-27 07:00:56.471 UTC [27] LOG:  checkpoint starting: time

2025-07-27 07:05:26.052 UTC [27] LOG:  checkpoint complete: wrote 5162 buffers (31.5%); 0 WAL file(s) added, 0 removed, 2 recycled; write=269.566 s, sync=0.007 s, total=269.581 s; sync files=51, longest=0.002 s, average=0.001 s; distance=42777 kB, estimate=42777 kB; lsn=0/8C329A18, redo lsn=0/8BAEEFC8

2025-07-27 07:05:56.081 UTC [27] LOG:  checkpoint starting: time

2025-07-27 07:07:40.556 UTC [27] LOG:  checkpoint complete: wrote 1046 buffers (6.4%); 0 WAL file(s) added, 0 removed, 1 recycled; write=104.463 s, sync=0.006 s, total=104.476 s; sync files=30, longest=0.005 s, average=0.001 s; distance=9552 kB, estimate=39454 kB; lsn=0/8C7CB530, redo lsn=0/8C443208

2025-07-27 07:10:56.656 UTC [27] LOG:  checkpoint starting: time

2025-07-27 07:13:13.175 UTC [27] LOG:  checkpoint complete: wrote 1117 buffers (6.8%); 0 WAL file(s) added, 0 removed, 0 recycled; write=115.964 s, sync=5.492 s, total=136.519 s; sync files=35, longest=1.267 s, average=0.157 s; distance=5914 kB, estimate=36100 kB; lsn=0/8D4A68A8, redo lsn=0/8CA09AD8

2025-07-27 07:15:56.274 UTC [27] LOG:  checkpoint starting: time

It seems the unresponsiveness comes in random intervals but mostly lasts for 5-10 minutes. When n8n becomes unresponsive while the frontend is still open, I can see the following messages:

Image

If I then reload the website I can see the following message: “Error 503, Database not ready”

I also made use of sqlite before trying to solve the underlying issue by switching to postgres. The n8n instance also became unresponsive with that setup. The error I got was different though, as it said “504 Gateway Timeout” while trying to reload the webpage in that unresponsive state. It is worth noting, that I do not have to restart any containers. The become responsive again on their own after 5-10 minutes.

Once n8n becomes responsive again I can see a few queued tasks, which I can not stop, as they just appear again with a different execution ID:

Image

Once I restart the container, those queued tasks are gone. As you can also see in the screenshot the MQTT Trigger, which is the only one in my “Power Metrics” workflow, triggers 3 times at once very often.

I am using Adguard Home as my DNS and network wide ad blocker. Are there any known conflicts with using n8n? The Mqtt node with how often it triggers could cause an overwhelming amount of traffic on the DNS..

To Reproduce

  1. Use my setup
  2. Let it run
  3. Check frontend in intervals and wait for it to become unresponsive
  4. Check InfluxDB instance for big gaps between datapoints to verify the workflows are also unresponsive

Expected behavior

A fluently and consistently running n8n instance

##[details=“instance information”]

Debug Info

Debug info

core

  • n8nVersion: 1.103.2
  • platform: docker (self-hosted)
  • nodeJsVersion: 22.17.0
  • database: postgres
  • executionMode: regular
  • concurrency: -1
  • license: enterprise (production)
  • consumerId: c41d4637-4f82-4b69-9cc7-5b4b042f14da

storage

  • success: all
  • error: all
  • progress: false
  • manual: true
  • binaryMode: memory

pruning

  • enabled: true
  • maxAge: 336 hours
  • maxCount: 10000 executions

client

  • userAgent: mozilla/5.0 (windows nt 10.0; win64; x64) applewebkit/537.36 (khtml, like gecko) chrome/138.0.0.0 safari/537.36
  • isTouchDevice: false

Generated at: 2025-07-27T07:11:16.038Z
[/details]

Operating System

Ubuntu 22.04.2 live server amd64 as VM inside Proxmox

n8n Version

1.103.2

Node.js Version

22.17.0

Database

PostgreSQL

Execution mode

main (default)

Hosting

self hosted

@sUBFUSC

Um, so my guess is some system env issues, are you using dockers? you mentioned containers but the offical n8n dockers? also what happening with system metrics do u have any spikes around same time it becomes unresponsive? it could be some resource utiliation causing it making container sleep when it thinkgs not in use maybe? or a workflow causing issues and crashing then resotring with backlog.

Is system metrics okay?

Samuel

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.