n8n 佇列模式:從叢集內 Redis 切換到外部 Aiven Valkey 後出現 PostgreSQL 連線逾時
描述問題/錯誤/疑問
摘要
在將 Redis 從叢集內部署遷移到外部 Aiven Valkey 後,n8n 開始出現 PostgreSQL 連線逾時的執行失敗。
在 Redis 遷移之前,相同的部署運作正常。(任務未被拾取但可運作)
環境
- 透過 Helm chart 部署的 n8n
- Kubernetes 叢集
- 已啟用佇列模式
- PostgreSQL 在叢集內執行
- Redis 已從叢集內 Redis 遷移到外部 Aiven Valkey
anton% kubectl get pods -n n8n
NAME READY STATUS RESTARTS AGE
n8n-77889b4756-9wqtq 1/1 Running 0 9m6s
n8n-postgresql-0 1/1 Running 0 112m
n8n-redis-master-0 1/1 Running 0 9m6s
n8n-webhook-7ffccd5dd8-njpnm 1/1 Running 1 (8m48s ago) 9m6s
n8n-worker-f7fff89fb-k45ff 1/1 Running 0 8m20s
n8n-worker-f7fff89fb-nv994 1/1 Running 1 (8m42s ago) 9m6s
錯誤訊息是什麼(如有的話)?
請分享你的工作流程
Lost Redis connection. Trying to reconnect in 1s...
Recovered Redis connection
Execution XX (job YY) failed
Error: timeout exceeded when trying to connect
簡單 Webhook
Error: timeout exceeded when trying to connect
at pg-pool/index.js:45
at PostgresDriver.obtainMasterConnection
at PostgresQueryRunner.query
at ExecutionRepository.findSingleExecution
at JobProcessor.processJob
變更內容
唯一的基礎設施變更是將 Redis 從叢集內 Redis 執行個體遷移到外部 Aiven Valkey。
遷移前:
- 佇列模式運作正常
- 執行成功完成
- 沒有 PostgreSQL 逾時錯誤
遷移後:
使用外部 Redis
使用叢集內 Redis
關於你的 n8n 設定的資訊
- n8n 版本: 2.25.7
- 資料庫(預設:postgresql):
- n8n EXECUTIONS_PROCESS 設定(預設:own, main):
- 執行 n8n 的方式 (kuber):
- 作業系統: Debian12
我在最新版本 v1 上試過 問題相同
嗨 @Antonio1
Aiven Valkey 需要特定的配置,這些配置與標準的集群內 Redis 部署不同。
- TLS/SSL 要求: Aiven 服務需要 TLS。確保你的 n8n 環境變數包含:
N8N_REDIS_TLS=true(或根據你的 n8n 版本/自訂映像的等效設定)。
- 如果你使用自訂連接字串,請確保它使用
rediss://(兩個 ‘s’)而不是 redis://。
- TCP 保活: 外部連接更容易被雲防火牆/負載平衡器中斷。確保你的 Kubernetes 節點具有適當的 TCP 保活設定,或檢查 Aiven 是否提供建議的保活間隔。
- 網路政策: 確認你的 Kubernetes 出口政策允許在 Valkey 連接埠(通常為 6379 或自訂 Aiven 連接埠)上到外部 Aiven IP 範圍的流量。
請告訴我這些是否有幫助
感謝你的回覆
是的,我知道我試過了
QUEUE_BULL_REDIS_CONNECTION_TIMEOUT: 30000
QUEUE_BULL_REDIS_TIMEOUT: 30000
QUEUE_BULL_REDIS_KEEP_ALIVE_DELAY: 15000
而且是的,我正在使用 Aiven 的 TLS
tls:
enabled: true
host: valkey-XXXXXXX.l.aivencloud.com
port: 21275
username: default
password: "PASS_HERE"
n8N 的日誌
Execution 29 (job 99) failed
Error: timeout exceeded when trying to connect
at /usr/local/lib/node_modules/n8n/node_modules/.pnpm/pg-pool@3.6.2_pg@8.12.0/node_modules/pg-pool/index.js:45:11
at PostgresDriver.obtainMasterConnection (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/@n8n+typeorm@0.3.20-15_@sentry+node@9.42.1_mysql2@3.15.0_pg@8.12.0_sqlite3@5.1.7/node_modules/src/driver/postgres/PostgresDriver.ts:1181:28)
at PostgresQueryRunner.query (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/@n8n+typeorm@0.3.20-15_@sentry+node@9.42.1_mysql2@3.15.0_pg@8.12.0_sqlite3@5.1.7/node_modules/src/driver/postgres/PostgresQueryRunner.ts:248:36)
at SelectQueryBuilder.loadRawResults (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/@n8n+typeorm@0.3.20-15_@sentry+node@9.42.1_mysql2@3.15.0_pg@8.12.0_sqlite3@5.1.7/node_modules/src/query-builder/SelectQueryBuilder.ts:3660:25)
at SelectQueryBuilder.getRawMany (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/@n8n+typeorm@0.3.20-15_@sentry+node@9.42.1_mysql2@3.15.0_pg@8.12.0_sqlite3@5.1.7/node_modules/src/query-builder/SelectQueryBuilder.ts:1617:29)
at SelectQueryBuilder.executeEntitiesAndRawResults (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/@n8n+typeorm@0.3.20-15_@sentry+node@9.42.1_mysql2@3.15.0_pg@8.12.0_sqlite3@5.1.7/node_modules/src/query-builder/SelectQueryBuilder.ts:3322:26)
at SelectQueryBuilder.getRawAndEntities (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/@n8n+typeorm@0.3.20-15_@sentry+node@9.42.1_mysql2@3.15.0_pg@8.12.0_sqlite3@5.1.7/node_modules/src/query-builder/SelectQueryBuilder.ts:1661:29)
at SelectQueryBuilder.getOne (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/@n8n+typeorm@0.3.20-15_@sentry+node@9.42.1_mysql2@3.15.0_pg@8.12.0_sqlite3@5.1.7/node_modules/src/query-builder/SelectQueryBuilder.ts:1688:25)
at ExecutionRepository.findSingleExecution (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/@n8n+db@file+packages+@n8n+db_@opentelemetry+api@1.9.0_@opentelemetry+sdk-trace-base@1._ab22bba05a964211b9fe14bf4b841570/node_modules/@n8n/db/src/repositories/execution.repository.ts:315:21)
at JobProcessor.processJob (/usr/local/lib/node_modules/n8n/src/scaling/job-processor.ts:57:21)
執行 29 出現問題:錯誤:嘗試連線時逾時。正在中止。
Error: timeout exceeded when trying to connect (execution 29)
Error: Error: timeout exceeded when trying to connect
at Queue.onFailed (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/bull@4.16.4_patch_hash=a4b6d56db16fe5870646929938466d6a5c668435fd1551bed6a93fffb597ba42/node_modules/bull/lib/job.js:523:18)
at processTicksAndRejections (node:internal/process/task_queues:104:5)
Execution 30 (job 100) failed
Error: timeout exceeded when trying to connect
at /usr/local/lib/node_modules/n8n/node_modules/.pnpm/pg-pool@3.11.0_pg@8.17.0/node_modules/pg-pool/index.js:45:11
at PostgresDriver.obtainMasterConnection (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/@n8n+typeorm@0.3.20-16_@sentry+node@10.36.0_mysql2@3.17.0_pg@8.17.0_sqlite3@5.1.7/node_modules/src/driver/postgres/PostgresDriver.ts:1182:28)
at PostgresQueryRunner.query (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/@n8n+typeorm@0.3.20-16_@sentry+node@10.36.0_mysql2@3.17.0_pg@8.17.0_sqlite3@5.1.7/node_modules/src/driver/postgres/PostgresQueryRunner.ts:248:36)
at SelectQueryBuilder.loadRawResults (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/@n8n+typeorm@0.3.20-16_@sentry+node@10.36.0_mysql2@3.17.0_pg@8.17.0_sqlite3@5.1.7/node_modules/src/query-builder/SelectQueryBuilder.ts:3660:25)
at SelectQueryBuilder.getRawMany (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/@n8n+typeorm@0.3.20-16_@sentry+node@10.36.0_mysql2@3.17.0_pg@8.17.0_sqlite3@5.1.7/node_modules/src/query-builder/SelectQueryBuilder.ts:1617:29)
at SelectQueryBuilder.executeEntitiesAndRawResults (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/@n8n+typeorm@0.3.20-16_@sentry+node@10.36.0_mysql2@3.17.0_pg@8.17.0_sqlite3@5.1.7/node_modules/src/query-builder/SelectQueryBuilder.ts:3322:26)
at SelectQueryBuilder.getRawAndEntities (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/@n8n+typeorm@0.3.20-16_@sentry+node@10.36.0_mysql2@3.17.0_pg@8.17.0_sqlite3@5.1.7/node_modules/src/query-builder/SelectQueryBuilder.ts:1661:29)
at SelectQueryBuilder.getOne (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/@n8n+typeorm@0.3.20-16_@sentry+node@10.36.0_mysql2@3.17.0_pg@8.17.0_sqlite3@5.1.7/node_modules/src/query-builder/SelectQueryBuilder.ts:1688:25)
可能嗎?
Job 在 Redis 中卡住 ↓
Main n8n 看到執行狀態為「running」↓
嘗試從 PostgreSQL 讀取以顯示狀態 ↓
pg-pool 超時——因為許多這樣的「掛起」請求同時堆積
是的,那個形狀是可能的,但你貼的追蹤資料是 pg-pool,所以下一個瓶頸是 Postgres 在 worker 並行下的容量,而不是另一個 Redis 逾時設定。幾個卡住的任務可以讓執行讀操作保持開啟的時間足夠長,使得 main/webhook/workers 都觸及同一個資料庫上限。
有個小檢查:有多少個 workers 在運行,DB_POSTGRESDB_POOL_SIZE 是多少,Postgres max_connections 在保留位置之後是多少?如果連接池的數學運算已經很緊張,Valkey 就暴露了資料庫的瓶頸。
@Antonio1
你需要為資料庫連線提供更多「呼吸空間」,這樣即使 worker 行為不當,狀態檢查也能成功。
- 在你的 n8n 部署中設定以下環境變數:
DB_POSTGRESDB_POOL_SIZE: "50"(或更高,取決於你的總 worker 數量)。
- 關鍵: 確保你的 PostgreSQL
max_connections(在 postgresql.conf 或你的雲端提供商設定中)至少設定為 (pod_數量 * DB_POSTGRESDB_POOL_SIZE) + 20。
由於你使用的是 Aiven,在重新連線事件期間 TLS 握手可能是瓶頸。
- 增加 Redis 連線逾時: 你已將
QUEUE_BULL_REDIS_CONNECTION_TIMEOUT 設定為 30 秒。試著將其增加至 60000(60 秒),以便在公網上進行較慢的 TLS 握手。
- 停用 Redis 叢集模式(如適用): 如果你沒有明確使用 Valkey/Redis 叢集,請確保 n8n 設定為單一節點連線。
- 檢查 Aiven 指標: 登入你的 Aiven 控制台,檢查你 Valkey 服務的**「連線數量」和「CPU 使用率」**。如果在你的 n8n worker 失敗的時間內看到尖峰,你可能已達到 Aiven 端的連線限制。
好的,我剛剛再測試了一次,只用了一個 POST
在執行標籤中,這個 POST 顯示為 佇列 然後 失敗
這個 n8n 上沒有其他工作流程,我只是在這裡試著使用佇列模式
這個工作沒有出現在任何工作程序上
它只是在主要 N8n Pod 上失敗
Lost Redis connection. Trying to reconnect in 1s... (0s/10s)
Recovered Redis connection
Enqueued execution 122 (job 166)
Execution 122 (job 166) failed
Error: timeout exceeded when trying to connect
at /usr/local/lib/node_modules/n8n/node_modules/.pnpm/pg-pool@3.6.2_pg@8.12.0/node_modules/pg-pool/index.js:45:11
at PostgresDriver.obtainMasterConnection (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/@n8n+typeorm@0.3.20-15_@sentry+node@9.42.1_mysql2@3.15.0_pg@8.12.0_sqlite3@5.1.7/node_modules/src/driver/postgres/PostgresDriver.ts:1181:28)
at PostgresQueryRunner.query (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/@n8n+typeorm@0.3.20-15_@sentry+node@9.42.1_mysql2@3.15.0_pg@8.12.0_sqlite3@5.1.7/node_modules/src/driver/postgres/PostgresQueryRunner.ts:248:36)
at SelectQueryBuilder.loadRawResults (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/@n8n+typeorm@0.3.20-15_@sentry+node@9.42.1_mysql2@3.15.0_pg@8.12.0_sqlite3@5.1.7/node_modules/src/query-builder/SelectQueryBuilder.ts:3660:25)
at SelectQueryBuilder.getRawMany (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/@n8n+typeorm@0.3.20-15_@sentry+node@9.42.1_mysql2@3.15.0_pg@8.12.0_sqlite3@5.1.7/node_modules/src/query-builder/SelectQueryBuilder.ts:1617:29)
at SelectQueryBuilder.executeEntitiesAndRawResults (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/@n8n+typeorm@0.3.20-15_@sentry+node@9.42.1_mysql2@3.15.0_pg@8.12.0_sqlite3@5.1.7/node_modules/src/query-builder/SelectQueryBuilder.ts:3322:26)
at SelectQueryBuilder.getRawAndEntities (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/@n8n+typeorm@0.3.20-15_@sentry+node@9.42.1_mysql2@3.15.0_pg@8.12.0_sqlite3@5.1.7/node_modules/src/query-builder/SelectQueryBuilder.ts:1661:29)
at SelectQueryBuilder.getOne (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/@n8n+typeorm@0.3.20-15_@sentry+node@9.42.1_mysql2@3.15.0_pg@8.12.0_sqlite3@5.1.7/node_modules/src/query-builder/SelectQueryBuilder.ts:1688:25)
at ExecutionRepository.findSingleExecution (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/@n8n+db@file+packages+@n8n+db_@opentelemetry+api@1.9.0_@opentelemetry+sdk-trace-base@1._ab22bba05a964211b9fe14bf4b841570/node_modules/@n8n/db/src/repositories/execution.repository.ts:315:21)
at JobProcessor.processJob (/usr/local/lib/node_modules/n8n/src/scaling/job-processor.ts:57:21)
Problem with execution 122: Error: timeout exceeded when trying to connect. Aborting.
Error: timeout exceeded when trying to connect (execution 122)
Error: Error: timeout exceeded when trying to connect
at Queue.onFailed (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/bull@4.16.4_patch_hash=a4b6d56db16fe5870646929938466d6a5c668435fd1551bed6a93fffb597ba42/node_modules/bull/lib/job.js:523:18)
at processTicksAndRejections (node:internal/process/task_queues:104:5)
Lost Redis connection. Trying to reconnect in 1s... (0s/10s)
Recovered Redis connection
這改變了讀取方式。如果一次測試執行從未在任何 worker 上執行,這還不是 Postgres pool-size 問題。該工作被排入隊列,但 worker 端未能保持足夠長的時間連接到相同的 Redis/Valkey 隊列以領取它。
發佈一條 worker 啟動日誌行,其中顯示它以隊列模式連接,以及 EXECUTIONS_MODE、QUEUE_BULL_REDIS_HOST/PORT/TLS 和 QUEUE_BULL_PREFIX(移除機密)。首先要確認的是主程序和 worker 指向的是完全相同的隊列配置,而不只是相同的 Valkey 主機。
@Antonio1
在 n8n 工作流程中管理狀態指標和記憶體問題需要清潔、模組化的架構,特別是在跨 Google Docs 和 Sheets 同步複雜資料時。
如果您想簡化此邏輯或需要強大的生產就緒解決方案來穩定您的 AI 代理,讓我們聯繫。
我專門構建和優化高效能的 n8n、AI、Make.com 和 GHL 自動化系統
EXECUTIONS_MODE
{26-06-12 12:52}Antons-MacBook-Pro-2:~ anton% for pod in $(kubectl get pods -n n8n -o name); do
echo "=== $pod ==="
kubectl exec -n n8n ${pod#pod/} -- env | grep EXECUTIONS_MODE
done
=== pod/n8n-564fbc565f-lxnsc ===
已預設容器「n8n-main」,共有:n8n-main、npm-install (init)
EXECUTIONS_MODE=queue
=== pod/n8n-postgresql-0 ===
=== pod/n8n-webhook-6bfc9f5cd8-dcv7l ===
EXECUTIONS_MODE=queue
=== pod/n8n-worker-7fb4c7d87d-jzwth ===
已預設容器「n8n-worker」,共有:n8n-worker、npm-install (init)
EXECUTIONS_MODE=queue
=== pod/n8n-worker-7fb4c7d87d-k82xw ===
已預設容器「n8n-worker」,共有:n8n-worker、npm-install (init)
EXECUTIONS_MODE=queue
=== pod/n8n-worker-7fb4c7d87d-kkdm9 ===
已預設容器「n8n-worker」,共有:n8n-worker、npm-install (init)
EXECUTIONS_MODE=queue
=== pod/n8n-worker-7fb4c7d87d-lqt7j ===
已預設容器「n8n-worker」,共有:n8n-worker、npm-install (init)
EXECUTIONS_MODE=queue
=== pod/n8n-worker-7fb4c7d87d-mspxz ===
已預設容器「n8n-worker」,共有:n8n-worker、npm-install (init)
EXECUTIONS_MODE=queue
=== pod/n8n-worker-7fb4c7d87d-xqcr2 ===
已預設容器「n8n-worker」,共有:n8n-worker、npm-install (init)
EXECUTIONS_MODE=queue
且
{26-06-12 12:52}Antons-MacBook-Pro-2:~ anton% for pod in $(kubectl get pods -n n8n -o name); do
echo "=== $pod ==="
kubectl exec -n n8n ${pod#pod/} -- env | grep QUEUE_BULL_
done
=== pod/n8n-564fbc565f-lxnsc ===
已預設容器「n8n-main」,共有:n8n-main、npm-install (init)
QUEUE_BULL_SETTINGS_LOCK_RENEW_TIME=30000
QUEUE_BULL_REDIS_DUALSTACK=false
QUEUE_BULL_REDIS_TIMEOUT=30000
QUEUE_BULL_REDIS_USERNAME=default
QUEUE_BULL_REDIS_PASSWORD=PASSWORD_SECURE
QUEUE_BULL_REDIS_CONNECTION_TIMEOUT=30000
QUEUE_BULL_SETTINGS_LOCK_DURATION=60000
QUEUE_BULL_REDIS_PORT=21275
QUEUE_BULL_SETTINGS_STALLED_INTERVAL=60000
QUEUE_BULL_REDIS_HOST=valkey-757370-XXXX.l.aivencloud.com
QUEUE_BULL_REDIS_KEEP_ALIVE_DELAY=15000
QUEUE_BULL_REDIS_DB=0
QUEUE_BULL_REDIS_TLS=true
=== pod/n8n-postgresql-0 ===
=== pod/n8n-webhook-6bfc9f5cd8-dcv7l ===
QUEUE_BULL_REDIS_PASSWORD=PASSWORD_SECURE
QUEUE_BULL_REDIS_KEEP_ALIVE_DELAY=15000
QUEUE_BULL_REDIS_CONNECTION_TIMEOUT=30000
QUEUE_BULL_REDIS_PORT=21275
QUEUE_BULL_REDIS_DB=0
QUEUE_BULL_SETTINGS_LOCK_DURATION=60000
QUEUE_BULL_SETTINGS_STALLED_INTERVAL=60000
QUEUE_BULL_REDIS_TLS=true
QUEUE_BULL_REDIS_DUALSTACK=false
QUEUE_BULL_SETTINGS_LOCK_RENEW_TIME=30000
QUEUE_BULL_REDIS_USERNAME=default
QUEUE_BULL_REDIS_TIMEOUT=30000
QUEUE_BULL_REDIS_HOST=valkey-757370-XXXX.l.aivencloud.com
=== pod/n8n-worker-7fb4c7d87d-jzwth ===
已預設容器「n8n-worker」,共有:n8n-worker、npm-install (init)
QUEUE_BULL_REDIS_HOST=valkey-757370-XXXX.l.aivencloud.com
QUEUE_BULL_REDIS_USERNAME=default
QUEUE_BULL_REDIS_PASSWORD=PASSWORD_SECURE
QUEUE_BULL_REDIS_KEEP_ALIVE_DELAY=15000
QUEUE_BULL_REDIS_TLS=true
QUEUE_BULL_SETTINGS_LOCK_RENEW_TIME=30000
QUEUE_BULL_SETTINGS_LOCK_DURATION=60000
QUEUE_BULL_REDIS_DB=0
QUEUE_BULL_SETTINGS_STALLED_INTERVAL=60000
QUEUE_BULL_REDIS_TIMEOUT=30000
QUEUE_BULL_REDIS_DUALSTACK=false
QUEUE_BULL_REDIS_PORT=21275
QUEUE_BULL_REDIS_CONNECTION_TIMEOUT=30000
=== pod/n8n-worker-7fb4c7d87d-k82xw ===
已預設容器「n8n-worker」,共有:n8n-worker、npm-install (init)
QUEUE_BULL_REDIS_KEEP_ALIVE_DELAY=15000
QUEUE_BULL_REDIS_TIMEOUT=30000
QUEUE_BULL_REDIS_DB=0
QUEUE_BULL_REDIS_DUALSTACK=false
QUEUE_BULL_REDIS_USERNAME=default
QUEUE_BULL_SETTINGS_LOCK_DURATION=60000
QUEUE_BULL_REDIS_PASSWORD=PASSWORD_SECURE
QUEUE_BULL_REDIS_HOST=valkey-757370-XXXX.l.aivencloud.com
QUEUE_BULL_REDIS_TLS=true
QUEUE_BULL_REDIS_PORT=21275
QUEUE_BULL_SETTINGS_STALLED_INTERVAL=60000
QUEUE_BULL_REDIS_CONNECTION_TIMEOUT=30000
QUEUE_BULL_SETTINGS_LOCK_RENEW_TIME=30000
=== pod/n8n-worker-7fb4c7d87d-kkdm9 ===
已預設容器「n8n-worker」,共有:n8n-worker、npm-install (init)
QUEUE_BULL_REDIS_DUALSTACK=false
QUEUE_BULL_REDIS_USERNAME=default
QUEUE_BULL_REDIS_DB=0
QUEUE_BULL_SETTINGS_LOCK_RENEW_TIME=30000
QUEUE_BULL_REDIS_PORT=21275
QUEUE_BULL_REDIS_TLS=true
QUEUE_BULL_REDIS_KEEP_ALIVE_DELAY=15000
QUEUE_BULL_SETTINGS_STALLED_INTERVAL=60000
QUEUE_BULL_SETTINGS_LOCK_DURATION=60000
QUEUE_BULL_REDIS_PASSWORD=PASSWORD_SECURE
QUEUE_BULL_REDIS_HOST=valkey-757370-XXXX.l.aivencloud.com
QUEUE_BULL_REDIS_TIMEOUT=30000
QUEUE_BULL_REDIS_CONNECTION_TIMEOUT=30000
=== pod/n8n-worker-7fb4c7d87d-lqt7j ===
已預設容器「n8n-worker」,共有:n8n-worker、npm-install (init)
QUEUE_BULL_SETTINGS_LOCK_DURATION=60000
QUEUE_BULL_REDIS_PASSWORD=PASSWORD_SECURE
QUEUE_BULL_REDIS_CONNECTION_TIMEOUT=30000
QUEUE_BULL_SETTINGS_STALLED_INTERVAL=60000
QUEUE_BULL_REDIS_USERNAME=default
QUEUE_BULL_REDIS_TLS=true
QUEUE_BULL_REDIS_DUALSTACK=false
QUEUE_BULL_SETTINGS_LOCK_RENEW_TIME=30000
QUEUE_BULL_REDIS_TIMEOUT=30000
QUEUE_BULL_REDIS_HOST=valkey-757370-XXXX.l.aivencloud.com
QUEUE_BULL_REDIS_KEEP_ALIVE_DELAY=15000
QUEUE_BULL_REDIS_DB=0
QUEUE_BULL_REDIS_PORT=21275
=== pod/n8n-worker-7fb4c7d87d-mspxz ===
已預設容器「n8n-worker」,共有:n8n-worker、npm-install (init)
QUEUE_BULL_REDIS_HOST=valkey-757370-XXXX.l.aivencloud.com
QUEUE_BULL_REDIS_DUALSTACK=false
QUEUE_BULL_REDIS_USERNAME=default
QUEUE_BULL_SETTINGS_LOCK_RENEW_TIME=30000
QUEUE_BULL_REDIS_CONNECTION_TIMEOUT=30000
QUEUE_BULL_REDIS_PORT=21275
QUEUE_BULL_REDIS_TLS=true
QUEUE_BULL_REDIS_PASSWORD=PASSWORD_SECURE
QUEUE_BULL_REDIS_TIMEOUT=30000
QUEUE_BULL_REDIS_DB=0
QUEUE_BULL_SETTINGS_LOCK_DURATION=60000
QUEUE_BULL_SETTINGS_STALLED_INTERVAL=60000
QUEUE_BULL_REDIS_KEEP_ALIVE_DELAY=15000
=== pod/n8n-worker-7fb4c7d87d-xqcr2 ===
已預設容器「n8n-worker」,共有:n8n-worker、npm-install (init)
QUEUE_BULL_REDIS_DUALSTACK=false
QUEUE_BULL_REDIS_KEEP_ALIVE_DELAY=15000
QUEUE_BULL_REDIS_TLS=true
QUEUE_BULL_REDIS_TIMEOUT=30000
QUEUE_BULL_REDIS_DB=0
QUEUE_BULL_SETTINGS_STALLED_INTERVAL=60000
QUEUE_BULL_REDIS_PASSWORD=PASSWORD_SECURE
QUEUE_BULL_SETTINGS_LOCK_DURATION=60000
QUEUE_BULL_SETTINGS_LOCK_RENEW_TIME=30000
QUEUE_BULL_REDIS_HOST=valkey-757370-XXXX.l.aivencloud.com
QUEUE_BULL_REDIS_PORT=21275
QUEUE_BULL_REDIS_CONNECTION_TIMEOUT=30000
QUEUE_BULL_REDIS_USERNAME=default
那些 env dumps 很有用:main、webhook 和 workers 現在都指向同一個 Valkey 佇列,所以這看起來不再像是 pods 之間有不同的 Redis 主機/連接埠/TLS 設定的問題。
那兩行遺漏的日誌是 worker 側實際啟動/聲稱工作的部分和 DB 連接池上限。貼一份 worker 在啟動/job 166 左右的日誌,加上 DB_POSTGRESDB_POOL_SIZE 和 Postgres 的 max_connections;有六個 workers 時,即使 Redis 設定相符,較小的 Postgres 連接池/max_connections 仍然可能導致故障呈現為 pg-pool。
{26-06-12 15:07}Antons-MacBook-Pro-2:~ anton% kubectl get pods -n n8n
NAME READY STATUS RESTARTS AGE
n8n-6687b7fb7d-vj2xr 1/1 Running 0 42s
n8n-postgresql-0 1/1 Running 0 17h
n8n-worker-7c5c5d5dc-x2x9d 1/1 Running 0 42s
好的,所以我把它簡化得很簡單
一個主節點 + 一個worker(postgresql 在集群中 )
=Worker=
與 job 124 無關
Concurrency is set to less than 5. THIS CAN LEAD TO AN UNSTABLE ENVIRONMENT. Please consider increasing it to at least 5 to make best use of the worker.
n8n Task Broker ready on 127.0.0.1, port 5679
Failed to start Python task runner in internal mode. because Python 3 is missing from this system. Launching a Python runner in internal mode is intended only for debugging and is not recommended for production. Users are encouraged to deploy in external mode. See:
[license SDK] Skipping renewal on init: renewOnInit is disabled in config
[license SDK] Skipping renewal on init: autoRenewEnabled is disabled in config
[license SDK] Skipping renewal on init: license cert is not initialized
Instance registered
Discovered 4 cluster checks
n8n worker server listening on port 5678
n8n worker is now ready
* Version: 2.25.7
* Concurrency: 2
Registered runner "JS Task Runner" (oqClB5JFV1-IPGaVNCRFu)
Worker started execution 123 (job 167)
Worker finished execution 123 (job 167)
=主節點=
execution 124
Defaulted container "n8n-main" out of: n8n-main, npm-install (init)
Initializing n8n process
n8n ready on ::, port 5678
[license SDK] Skipping renewal on init: license cert is not initialized
Attempting to reinstall missing packages
Failed to execute npm command
Failed to reinstall community package n8n-nodes-minio: Failed to execute npm command
Failed to execute npm command
Failed to reinstall community package n8n-nodes-firebird: Failed to execute npm command
Instance registered
Discovered 4 cluster checks
Cluster check warning Detected 2 instances claiming leader role: 0490eef8-9207-4ef7-a379-4699f18e001c, 2586c901-fd3c-4c06-a190-a4197e69f325
Currently active workflows:
- My workflow (ID: QFQvCXo8mBhadrAM)
Version: 2.25.7
Building workflow dependency index...
Start Active Workflows:
Finished building workflow dependency index. Processed 0 draft workflows, 0 published workflows.
Activated workflow "My workflow" (ID: QFQvCXo8mBhadrAM)
Editor is now accessible via:
URL-HERE
Enqueued execution 123 (job 167)
Execution 123 (job 167) finished
Enqueued execution 124 (job 168)
User attempted to access a workflow without permissions
Execution 124 (job 168) failed
Error: timeout exceeded when trying to connect
at /usr/local/lib/node_modules/n8n/node_modules/.pnpm/pg-pool@3.6.2_pg@8.12.0/node_modules/pg-pool/index.js:45:11
at PostgresDriver.obtainMasterConnection (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/@n8n+typeorm@0.3.20-15_@sentry+node@9.42.1_mysql2@3.15.0_pg@8.12.0_sqlite3@5.1.7/node_modules/src/driver/postgres/PostgresDriver.ts:1181:28)
at PostgresQueryRunner.query (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/@n8n+typeorm@0.3.20-15_@sentry+node@9.42.1_mysql2@3.15.0_pg@8.12.0_sqlite3@5.1.7/node_modules/src/driver/postgres/PostgresQueryRunner.ts:248:36)
at SelectQueryBuilder.loadRawResults (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/@n8n+typeorm@0.3.20-15_@sentry+node@9.42.1_mysql2@3.15.0_pg@8.12.0_sqlite3@5.1.7/node_modules/src/query-builder/SelectQueryBuilder.ts:3660:25)
at SelectQueryBuilder.getRawMany (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/@n8n+typeorm@0.3.20-15_@sentry+node@9.42.1_mysql2@3.15.0_pg@8.12.0_sqlite3@5.1.7/node_modules/src/query-builder/SelectQueryBuilder.ts:1617:29)
at SelectQueryBuilder.executeEntitiesAndRawResults (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/@n8n+typeorm@0.3.20-15_@sentry+node@9.42.1_mysql2@3.15.0_pg@8.12.0_sqlite3@5.1.7/node_modules/src/query-builder/SelectQueryBuilder.ts:3322:26)
at SelectQueryBuilder.getRawAndEntities (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/@n8n+typeorm@0.3.20-15_@sentry+node@9.42.1_mysql2@3.15.0_pg@8.12.0_sqlite3@5.1.7/node_modules/src/query-builder/SelectQueryBuilder.ts:1661:29)
at SelectQueryBuilder.getOne (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/@n8n+typeorm@0.3.20-15_@sentry+node@9.42.1_mysql2@3.15.0_pg@8.12.0_sqlite3@5.1.7/node_modules/src/query-builder/SelectQueryBuilder.ts:1688:25)
at ExecutionRepository.findSingleExecution (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/@n8n+db@file+packages+@n8n+db_@opentelemetry+api@1.9.0_@opentelemetry+sdk-trace-base@1._ab22bba05a964211b9fe14bf4b841570/node_modules/@n8n/db/src/repositories/execution.repository.ts:315:21)
at JobProcessor.processJob (/usr/local/lib/node_modules/n8n/src/scaling/job-processor.ts:57:21)
Problem with execution 124: Error: timeout exceeded when trying to connect. Aborting.
Error: timeout exceeded when trying to connect (execution 124)
Error: Error: timeout exceeded when trying to connect
at Queue.onFailed (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/bull@4.16.4_patch_hash=a4b6d56db16fe5870646929938466d6a5c668435fd1551bed6a93fffb597ba42/node_modules/bull/lib/job.js:523:18)
at processTicksAndRejections (node:internal/process/task_queues:104:5)
User attempted to access a workflow without permissions
User attempted to access a workflow without permissions
Lost Redis connection. Trying to reconnect in 1s... (0s/10s)
Recovered Redis connection
Lost Redis connection. Trying to reconnect in 1s... (0s/10s)
Recovered Redis connection
125 OK
所以這是某種隨機的
==Worker==
n8n worker is now ready
Version: 2.25.7
Concurrency: 2
Registered runner "JS Task Runner" (oqClB5JFV1-IPGaVNCRFu)
Worker started execution 123 (job 167)
Worker finished execution 123 (job 167)
Lost Redis connection. Trying to reconnect in 1s... (0s/10s)
Recovered Redis connection
Recovered Redis connection
Lost Redis connection. Trying to reconnect in 1s... (0s/10s)
Recovered Redis connection
Lost Redis connection. Trying to reconnect in 1s... (0s/10s)
Recovered Redis connection
Recovered Redis connection
Lost Redis connection. Trying to reconnect in 1s... (0s/10s)
Recovered Redis connection
Worker started execution 125 (job 169)
Worker finished execution 125 (job 169)
=Main=
Problem with execution 124: Error: timeout exceeded when trying to connect. Aborting.
Error: timeout exceeded when trying to connect (execution 124)
Error: Error: timeout exceeded when trying to connect
at Queue.onFailed (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/bull@4.16.4_patch_hash=a4b6d56db16fe5870646929938466d6a5c668435fd1551bed6a93fffb597ba42/node_modules/bull/lib/job.js:523:18)
at processTicksAndRejections (node:internal/process/task_queues:104:5)
User attempted to access a workflow without permissions
User attempted to access a workflow without permissions
Lost Redis connection. Trying to reconnect in 1s... (0s/10s)
Recovered Redis connection
Lost Redis connection. Trying to reconnect in 1s... (0s/10s)
Recovered Redis connection
Lost Redis connection. Trying to reconnect in 1s... (0s/10s)
Recovered Redis connection
Lost Redis connection. Trying to reconnect in 1s... (0s/10s)
Recovered Redis connection
Lost Redis connection. Trying to reconnect in 1s... (0s/10s)
Recovered Redis connection
Lost Redis connection. Trying to reconnect in 1s... (0s/10s)
Recovered Redis connection
Lost Redis connection. Trying to reconnect in 1s... (0s/10s)
Recovered Redis connection
Lost Redis connection. Trying to reconnect in 1s... (0s/10s)
Recovered Redis connection
Lost Redis connection. Trying to reconnect in 1s... (0s/10s)
Recovered Redis connection
Enqueued execution 125 (job 169)
Execution 125 (job 169) finished
User attempted to access a workflow without permissions
我進行了額外的測試
我在 n8n 工作區內啟動了一個新的 pod
redis-cli
-h ``valkey-XXXX.l.aivencloud.com``
-p 21275
--tls
--user default
-a 'YOUR_PASSWORD'
SUBSCRIBE test
然後使用我電腦上的另一個 CLIENT 來發送事件
while true; do
redis-cli
-h ``valkey-XXXX.l.aivencloud.com``
-p 21275
--tls
--user default
-a 'YOUR_PASSWORD'
PUBLISH test hello
sleep 1
done
=結果=
新 pod 未中斷與 redis 的連線
-
“hello”
-
“message”
-
“test”
-
“hello”
-
“message”
-
“test”
-
“hello”
-
“message”
-
“test”
=Worker n8n 方面=
Redis 連線已恢復
Redis 連線已中斷。正在嘗試在 1 秒內重新連線... (0 秒/10 秒)
Redis 連線已恢復
Redis 連線已中斷。正在嘗試在 1 秒內重新連線... (0 秒/10 秒)
Redis 連線已恢復
Redis 連線已中斷。正在嘗試在 1 秒內重新連線... (0 秒/10 秒)
Redis 連線已恢復
Redis 連線已中斷。正在嘗試在 1 秒內重新連線... (0 秒/10 秒)
Redis 連線已恢復
Redis 連線已恢復
Redis 連線已中斷。正在嘗試在 1 秒內重新連線... (0 秒/10 秒)
Redis 連線已恢復
Redis 連線已中斷。正在嘗試在 1 秒內重新連線... (0 秒/10 秒)
Redis 連線已恢復
Redis 連線已中斷。正在嘗試在 1 秒內重新連線... (0 秒/10 秒)
Redis 連線已恢復
Redis 連線已中斷。正在嘗試在 1 秒內重新連線... (0 秒/10 秒)
Redis 連線已恢復
Redis 連線已恢復
Redis 連線已中斷。正在嘗試在 1 秒內重新連線... (0 秒/10 秒)
Redis 連線已恢復
Redis 連線已中斷。正在嘗試在 1 秒內重新連線... (0 秒/10 秒)
Redis 連線已恢復
Redis 連線已中斷。正在嘗試在 1 秒內重新連線... (0 秒/10 秒)
Redis 連線已恢復
Redis 連線已中斷。正在嘗試在 1 秒內重新連線... (0 秒/10 秒)