Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Production void/db (Postgres/Hyperdrive) caches pg.Pool across requests → Worker hangs (1101) on every request after the first

Chiusa Adatta ai principianti
#74 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

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

Direzione di ricerca

Inizia in void/dist/index.mjs al template dialect === "postgresql" e confronta il ramo di produzione di getInstance() con il ramo locale. Riproduci richieste ripetute verso un isolate Cloudflare Workers attivo usando database: "pg" e verifica che le route supportate dal database non si blocchino più dopo la prima richiesta.

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

Descrizione

With database: "pg", the generated prod void/db caches its pg.Pool in module scope and reuses it across requests. That doesn't work on workerd: a TCP socket belongs to the request that opened it and is dead by the next one, so any query after the first in a warm isolate hangs and Cloudflare kills the request with:

1101 — "The Workers runtime canceled this request because it detected that your Worker's code had hung and would never generate a response."

In practice every DB-backed route 500s in prod as soon as the isolate warms up. no-DB routes are fine; the first request after a cold start works, everything after it hangs.

The generated module (void/dist/index.mjs, the dialect === "postgresql" template):

let _prodInstance;

function getInstance() {
  if (getRuntimeBinding("DATABASE_URL")) {
    // local dev: fresh pool per chain, because workerd kills sockets between requests
    return drizzle(new pg.Pool({ connectionString: getRuntimeBinding("DATABASE_URL"), max: 1 }), { schema });
  }
  // prod (Hyperdrive): cached across requests
  _prodInstance ??= drizzle(getConnectionString(), { schema });
  return _prodInstance;
}

The local branch comment already mentions the problem ("workerd kills TCP sockets between requests, so pg.Pool's cached connections go stale and hang").

Fix is to drop the cache and do what the local branch does:

function getInstance() {
  return drizzle(new pg.Pool({ connectionString: getConnectionString(), max: 1 }), { schema });
}

Hyperdrive pools on the origin side anyway, so a fresh pool per chain is cheap. We're running this as a pnpm patch against [email protected] and it fixes the outage.

Env: [email protected], database: "pg" over Hyperdrive, deployed to Cloudflare Workers.

Lingua principale
TypeScript
Stelle
155
Fork
2
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

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 TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.