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

Abierto
#6,136 1 comentario 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
55/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
docker, postgresql, typescript

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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

Lenguaje dominante
TypeScript
Estrellas
38.8k
Forks
3.2k
Merge medio
1 d 10 h
PR fusionados (30 d)
110

Preparar el entorno

Abrir en Codespaces

Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de Dokploy/dokploy

Todos los issues de Dokploy/dokploy

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.