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

未关闭
#6,136 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
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 小时
30 天内合并 PR
110

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

Dokploy/dokploy 的其他 Issue

查看 Dokploy/dokploy 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。