[v0.29.8] [Bug]: postgres.js 3.4.4 schedules negative reconnect timeouts, emitting TimeoutNegativeWarning in the core process logs

オープン
#6,136 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
55/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
docker, postgresql, typescript
領域
backend, databases

調査の方向性

Start by checking the postgres versions in packages/server/package.json and apps/dokploy/package.json, then inspect the lockfile entries for the same dependency. The issue identifies the fix as updating both declarations from 3.4.4 to 3.4.8 and updating the lockfile; done means the resolved versions are 3.4.8 and the warning no longer appears on reconnect.

索引モデルが issue の本文から書いたものです。

説明

bug dependencies
To Reproduce
  1. Run any Dokploy instance (self-hosted, single node is enough). No applications
    need to be deployed.

  2. Follow the core process logs: docker service logs -f dokploy (Swarm) or
    docker logs -f <dokploy-container>.

  3. Force the pooled Postgres connection to drop and be reused after an idle gap.
    On a Swarm install:

    docker service scale dokploy-postgres=0
    # keep the panel open / click around for ~25 s so the pool notices the drop
    docker service scale dokploy-postgres=1
    
  4. The next query that reuses that pooled connection prints:

    (node:53) TimeoutNegativeWarning: -19224216.33660932 is a negative number.
    Timeout duration was set to 1.
    

    The magnitude is how long the connection had been sitting closed in the pool —
    -19224216 ms is 5 h 20 min. The longer the instance has been up, the larger it
    gets.

A driver-level reproduction that does not need a Dokploy instance at all:

docker run -d --name pgrepro -e POSTGRES_PASSWORD=repro -e POSTGRES_DB=repro \
  -p 55432:5432 postgres:16
// node repro.mjs, with [email protected] installed
import postgres from "postgres";
const sql = postgres("postgres://postgres:[email protected]:55432/repro", { max: 1 });
const admin = postgres("postgres://postgres:[email protected]:55432/repro", { max: 1 });
process.on("warning", (w) => console.log("WARNING:", w.name, w.message));
await sql`select 1`;
const [{ pid }] = await sql`select pg_backend_pid() as pid`;
await admin`select pg_terminate_backend(${pid})`;
await new Promise((r) => setTimeout(r, 50)); // idle past the 5-30 ms backoff
await sql`select 2`.catch(() => {});

On [email protected] this prints TimeoutNegativeWarning; on [email protected] it
does not.

Current vs. Expected behavior

Current: the core process periodically logs TimeoutNegativeWarning with a
large negative value. It comes from postgres.js 3.4.4, src/connection.js:353:

setTimeout(connect, closedDate ? closedDate + delay - performance.now() : 0)

closedDate is stamped when a pooled connection closes and is never reset, while
the default backoff is only 5–30 ms. Any connection reused more than a few
milliseconds after it closed therefore schedules a negative timeout, which Node
clamps to 1 ms and warns about. Dokploy calls postgres(dbUrl) with defaults,
including a max_lifetime of 30–60 min, so pooled connections do close and get
reused in normal operation.

Expected: no TimeoutNegativeWarning in the logs. The upstream clamp first
ships in postgres.js 3.4.8
(porsager/postgres@3ffc3c4).

Severity: low — this is log noise, not a performance problem. Worth stating
explicitly, because this warning was originally reported in #4661 together with
CPU spikes and the two turned out to be unrelated. The negative value replaces a
5–30 ms backoff with an immediate retry, once per reconnect — it is not a
loop. Measured over 150 forced reconnect cycles, three paired runs:

[3.4.4] 150 reconnect cycles | wall 11915ms | cpu 1795ms | 15.1% of one core | TimeoutNegativeWarning=1
[3.4.8] 150 reconnect cycles | wall 11758ms | cpu 1789ms | 15.2% of one core | TimeoutNegativeWarning=0
[3.4.4] 150 reconnect cycles | wall 12237ms | cpu 1815ms | 14.8% of one core | TimeoutNegativeWarning=1
[3.4.8] 150 reconnect cycles | wall 11821ms | cpu 1725ms | 14.6% of one core | TimeoutNegativeWarning=0
[3.4.4] 150 reconnect cycles | wall 11926ms | cpu 1667ms | 14.0% of one core | TimeoutNegativeWarning=1
[3.4.8] 150 reconnect cycles | wall 11720ms | cpu 1722ms | 14.7% of one core | TimeoutNegativeWarning=0

Identical within noise (1759 ms vs 1745 ms mean), and note the warning fires once
per 150 cycles, not once per cycle. Filing this only so the remaining half of
#4661 stays tracked after the CPU fix lands.

Provide environment information
Dokploy: reproduced in-situ on v0.29.4 (dokploy/dokploy:v0.29.4), self-hosted Swarm, single node
Affected dependency is unchanged on canary today:
  packages/server/package.json -> "postgres": "3.4.4"
  apps/dokploy/package.json    -> "postgres": "3.4.4"
  (3.4.7 also ships transitively and is still unfixed; the clamp lands in 3.4.8)
OS: Ubuntu, kernel 5.15.0 x86_64
Docker Engine: Swarm mode, single manager node
Driver-level repro is version-independent: [email protected] vs [email protected] against postgres:16
Which area(s) are affected? (Select all that apply)

Databases

Are you deploying the applications where Dokploy is installed or on a remote server?

Same server where Dokploy is installed

Additional context

This is the second of the two symptoms bundled in #4661. The CPU half of that
report has a separate root cause (overlapping docker stats polls in
apps/dokploy/server/wss/docker-stats.ts) and is fixed by #5011; the postgres
bump was deliberately dropped from that PR to keep it focused, which is why this
one exists.

Fix is a dependency bump only: postgres 3.4.4 → 3.4.8 in
packages/server/package.json and apps/dokploy/package.json, plus the lockfile.
Verified in-situ by rebuilding the v0.29.4 image with only postgres.js replaced
and rolling it into the Swarm service — the warning was gone and the panel worked
normally.

Will you send a PR to fix it?

No

主要言語
TypeScript
スター
38.8k
フォーク
3.2k
平均マージ
1日 10時間
マージ済み PR(30日)
110

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

Dokploy/dokploy のほかの issue

Dokploy/dokploy の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。