v4: a connection error without a stack (Bun DNSException) throws in withOrigin, so the query hangs forever and the pool never retries

Aperta Adatta ai principianti
#1,312 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
82/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
bun, javascript, postgresql

Direzione di ricerca

Inizia da src/errors.js:65 e segui come src/pool.js gestisce una connessione non riuscita tramite failed, attempted e reject. Riproduci il problema con Bun usando un nome host che non viene risolto, quindi verifica che la query venga rifiutata invece di restare bloccata; controlla anche che gli errori con uno stack mantengano il comportamento attuale del messaggio.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Summary

withOrigin (src/errors.js:65) assumes every connection error has a stack string. When it doesn't, it throws inside the pool's failure handling (failed → attempted → reject in src/pool.js). The pending query never settles, grow() is never reached so no retry happens, and the process hangs forever.

Bun's DNS errors have no stack (DNSException, e.g. EAI_AGAIN), so on Bun any query against a host that doesn't resolve hangs instead of rejecting.

Reproduction (postgres 4.1.0, Bun 1.4.4)

import postgres from 'postgres'
const sql = postgres('postgres://user:[email protected]:5432/db', { max: 1 })
await sql`select 1` // never settles

Output:

TypeError: undefined is not an object (evaluating 'error.stack.split')
      at withOrigin (node_modules/postgres/src/errors.js:65:19)
      at reject (node_modules/postgres/src/pool.js:575:58)
      at forEach (1:11)
      at attempted (node_modules/postgres/src/pool.js:570:71)
      at failed (node_modules/postgres/src/pool.js:557:5)

With ECONNREFUSED (an error that has a stack) the query rejects as expected.

Fix

Changing only that line makes the query reject in ~4 ms with EAI_AGAIN:

-    value: [error.stack.split('\n')[0], ...origin.split('\n').slice(1).filter(x => !ours(x))].join('\n'),
+    value: [String(error.stack ?? error.message).split('\n')[0], ...origin.split('\n').slice(1).filter(x => !ours(x))].join('\n'),

More generally, an exception thrown while rejecting jobs should not leave them pending.

Impact

We hit this in production: after a Docker Swarm host reboot, the database service name did not resolve for a few seconds when the app started. The startup query hung instead of failing, so the container never exited and Swarm never restarted it; the app was down for ~6 hours.

Lingua principale
JavaScript
Stelle
8.8k
Fork
404
Merge medio
21h 8m
PR unite (30g)
18

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Issue simili

Altre issue su JavaScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.