Random Service unavailable error while scaling

Describe the problem/error/question

I randomly get this Service Unavailable error.
When it happens, the following messages appear:

timeout exceeded when trying to connect
Error while saving insights metadata and raw data
Error in handling webhook request POST /webhook/befc7a55-9228-444c-a2e3-5ab24e5954d6: timeout exceeded when trying to connect

What could be done to mitigate that?

I Have about 30K workflow runs a day, I have already verified that the server is enough.

Dedicated: 4 core, 16 GB Ram, 400 GB NVME Hetzner.

I have set haproxy as a load balancer and distributed the load using the 3 webhook instances.

What is the error message (if any)?

Service unavailable - try again later or consider setting this node to retry automatically (in the node settings)

Please share your workflow

Im unable to share the workflow, the 32k char limit.

Share the output returned by the last node

Error details
Other info
n8n version
1.108.2 (Self Hosted)
Time
02/09/2025, 12:52:04

Information on your n8n setup

  • n8n version: 1.108.2
  • Database (default: SQLite): Postgres + PgBouncer
  • n8n EXECUTIONS_PROCESS setting (default: own, main): Main
  • Running n8n via (Docker, npm, n8n cloud, desktop app): Docker Compose
  • Operating system: Debian 13
  • Mode: Queue
  • Workers: 3
  • Webhook Workers: 3
  • Reverse Proxy: HAProxy

DOCKER COMPOSE

services:
  postgres:
    image: postgres:16.10
    env_file: db.env
    command: >
      postgres
      -c max_connections=100
      -c shared_buffers=2GB
      -c effective_cache_size=6GB
      -c maintenance_work_mem=1GB
      -c work_mem=64MB
      -c wal_level=replica
      -c wal_compression=on
      -c synchronous_commit=off
      -c checkpoint_timeout=15min
      -c max_wal_size=8GB
      -c autovacuum_naptime=10s
      -c autovacuum_vacuum_scale_factor=0.1
      -c autovacuum_analyze_scale_factor=0.05
    volumes:
      - n8n_pg_data:/var/lib/postgresql/data
    restart: unless-stopped

  pgbouncer:
    image: edoburu/pgbouncer:latest
    env_file: db.env
    restart: unless-stopped
    volumes:
      - ./pgbouncer.ini:/etc/pgbouncer/pgbouncer.ini:ro
      - ./userlist.txt:/etc/pgbouncer/userlist.txt:ro


  valkey:
    image: valkey/valkey:latest
    restart: unless-stopped

  main:
    image: n8nio/n8n:latest
    env_file: n8n.env
    restart: unless-stopped
    ports:
      - "5678:5678"
    volumes:
      - ./local-files:/files 

  worker:
    image: n8nio/n8n:latest
    env_file: n8n.env
    command: worker
    restart: unless-stopped


  webhook-1:
    image: n8nio/n8n:latest
    env_file: n8n.env
    command: webhook
    ports:
      - "5679:5678"
    restart: unless-stopped
  webhook-2:
    image: n8nio/n8n:latest
    env_file: n8n.env
    command: webhook
    ports:
      - "5680:5678"
    restart: unless-stopped
  webhook-3:
    image: n8nio/n8n:latest
    env_file: n8n.env
    command: webhook
    ports:
      - "5681:5678"
    restart: unless-stopped


volumes:
  n8n_pg_data:


DB ENV:

## POSTGRES
POSTGRES_DB=n8n
POSTGRES_USER=xxxxxxxxxxxxxxx
POSTGRES_PASSWORD=xxxxxxxxxxxxxxx

## PG_BOUNCER
PGBOUNCER_DB=n8n
PGBOUNCER_USER=xxxxxxxxxxxxxxx
PGBOUNCER_PASSWORD=xxxxxxxxxxxxxxx
PGBOUNCER_PORT=6432
PGBOUNCER_POOL_MODE=transaction
PGBOUNCER_DEFAULT_POOL_SIZE=50
PGBOUNCER_MIN_POOL_SIZE=10
PGBOUNCER_RESERVE_POOL_SIZE=10
PGBOUNCER_RESERVE_POOL_TIMEOUT=5

MAIN ENV:

### N8N

## DB
DB_TYPE=postgresdb
DB_POSTGRESDB_HOST=pgbouncer
DB_POSTGRESDB_PORT=6432
DB_POSTGRESDB_DATABASE=n8n
DB_POSTGRESDB_USER=xxxxxxxxxxxxxxxxxxxx
DB_POSTGRESDB_PASSWORD=xxxxxxxxxxxxxxxxxxx

## REDIS
QUEUE_BULL_REDIS_HOST=valkey
QUEUE_BULL_REDIS_PORT=6379

## N8N CONFIGS
N8N_ENCRYPTION_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxx
EXECUTIONS_MODE=queue

## Worker configs
N8N_CONCURRENCY=10
N8N_DISABLE_PRODUCTION_MAIN_PROCESS=true

## EXTRAS
WEBHOOK_URL=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
N8N_RUNNERS_ENABLED=false
OFFLOAD_MANUAL_EXECUTIONS_TO_WORKERS=true
N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS=true
N8N_PROXY_HOPS=1
EXECUTIONS_DATA_MAX_AGE=720
EXECUTIONS_DATA_PRUNE_MAX_COUNT=10000000

WORKER AND WEBHOOK ENV:

# === Webhook Worker (command: webhook) ===

## DB
DB_TYPE=postgresdb
DB_POSTGRESDB_HOST=pgbouncer
DB_POSTGRESDB_PORT=6432
DB_POSTGRESDB_DATABASE=n8n
DB_POSTGRESDB_USER=xxxxxxxxxxxxxxxxx
DB_POSTGRESDB_PASSWORD=xxxxxxxxxxxx

## REDIS
QUEUE_BULL_REDIS_HOST=valkey
QUEUE_BULL_REDIS_PORT=6379

## N8N (fila + criptografia)
EXECUTIONS_MODE=queue
N8N_ENCRYPTION_KEY=xxxxxxxxxxxxxxxxxx

## WORKER SPECIFIC
N8N_DISABLE_PRODUCTION_MAIN_PROCESS=true
WEBHOOK_URL=xxxxxxxxxxxxxxxxxx



it ramdonly occurs on one of the requests, but the requests point to the load balancer.

I have already checked and the load balancer seems ok.

UPDATE:

I reduced the JSON size and I was able to mitigate about 90% of the errors.

It seems to be a memory related error.

Is there a way to provision more ram to N8N?

I have read trough the documents changed the payload size from 16mb to 300mb, but didn’t seem to solve the problem. I guess a parameter needs to be passed to node.js.

What parameter would that be?

UPDATE 2:

Problem is still here

2025-09-29T13:08:28.631Z | error | Error in handling webhook request POST /webhook/580d0510-9aa8-482c-88ca-c547b535749f: timeout exceeded when trying to connect {“stacktrace”:“Error: timeout exceeded when trying to connect\n at /usr/local/lib/node_modules/n8n/node_modules/.pnpm/[email protected][email protected]/node_modules/pg-pool/index.js:45:11\n at runNextTicks (node:internal/process/task_queues:65:5)\n at processTimers (node:internal/timers:520:9)\n at PostgresDriver.obtainMasterConnection (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/@[email protected]_@[email protected][email protected][email protected]_@aws-sdk+creden_91044dc156940e71597cdc08f43e5a79/node_modules/src/driver/postgres/PostgresDriver.ts:1175:28)\n at PostgresQueryRunner.query (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/@[email protected]_@[email protected][email protected][email protected]_@aws-sdk+creden_91044dc156940e71597cdc08f43e5a79/node_modules/src/driver/postgres/PostgresQueryRunner.ts:248:36)\n at SelectQueryBuilder.loadRawResults (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/@[email protected]_@[email protected][email protected][email protected]_@aws-sdk+creden_91044dc156940e71597cdc08f43e5a79/node_modules/src/query-builder/SelectQueryBuilder.ts:3805:25)\n at SelectQueryBuilder.executeEntitiesAndRawResults (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/@[email protected]_@[email protected][email protected][email protected]_@aws-sdk+creden_91044dc156940e71597cdc08f43e5a79/node_modules/src/query-builder/SelectQueryBuilder.ts:3551:26)\n at SelectQueryBuilder.getRawAndEntities (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/@[email protected]_@[email protected][email protected][email protected]_@aws-sdk+creden_91044dc156940e71597cdc08f43e5a79/node_modules/src/query-builder/SelectQueryBuilder.ts:1670:29)\n at SelectQueryBuilder.getMany (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/@[email protected]_@[email protected][email protected][email protected]_@aws-sdk+creden_91044dc156940e71597cdc08f43e5a79/node_modules/src/query-builder/SelectQueryBuilder.ts:1760:25)\n at WebhookService.getWebhookMethods (/usr/local/lib/node_modules/n8n/src/webhooks/webhook.service.ts:138:25)\n at LiveWebhooks.getWebhookMethods (/usr/local/lib/node_modules/n8n/src/webhooks/live-webhooks.ts:41:10)\n at LiveWebhooks.findWebhook (/usr/local/lib/node_modules/n8n/src/webhooks/live-webhooks.ts:167:26)\n at LiveWebhooks.executeWebhook (/usr/local/lib/node_modules/n8n/src/webhooks/live-webhooks.ts:83:19)\n at WebhookRequestHandler.handleRequest (/usr/local/lib/node_modules/n8n/src/webhooks/webhook-request-handler.ts:65:21)\n at /usr/local/lib/node_modules/n8n/src/webhooks/webhook-request-handler.ts:230:3”,“file”:“webhook-request-handler.js”,“function”:“handleRequest”}

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