Task identifier cache keeps a rejected lookup forever, wedging the runner after a connection drop

Aperta Adatta ai principianti
#638 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

@agustin18 ci sta già lavorando.

Dal 23/11/2026.

  • #640 di @devtechedge — chiusa senza merge
  • #656 di @agustin18 — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
72/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
node.js, postgresql, typescript
Ambito
backend

Direzione di ricerca

Inizia in src/taskIdentifiers.ts: cache.lastStr e cache.lastDigest vengono impostati prima del lookup asincrono e non vengono mai cancellati quando quest'ultimo viene rifiutato, quindi getJobs attende lo stesso rifiuto a ogni poll. Leggi quella logica di cache insieme alla chiamata withPgClient.withRetries (che ritenta solo 40001/40P01/57P03/EHOSTUNREACH/ETIMEDOUT) e al logging di getJob a livello debug in worker.js. Riproduci terminando il backend del lookup con pg_terminate_backend e aggiungendo un job; done significa che il runner si riprende al poll successivo, idealmente con errori ripetuti registrati sopra debug.

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

Descrizione

Version: graphile-worker 0.18.0 (the same code is on main)

What happens

If the task-identifier lookup fails once (for example the Postgres backend is terminated with pg_terminate_backend, a failover, "Connection terminated unexpectedly", or a pool checkout timeout during the first poll after start), the runner never recovers. It keeps polling every pollInterval, each poll fails with the same error logged only at debug level, and jobs added afterwards never run. The runner promise never settles, so a supervisor has nothing to restart.

Cause

src/taskIdentifiers.ts sets cache.lastStr before the async lookup and stores the lookup's promise in cache.lastDigest. Nothing clears them when that promise rejects, so every later call returns the same rejected promise. The lookup runs through withPgClient.withRetries, which retries only 40001, 40P01, 57P03, EHOSTUNREACH and ETIMEDOUT; a 57P01 (admin shutdown) or a dropped connection fails once and is then cached. getJobs awaits that cached rejection on every poll, and worker.js logs it at debug.

Reproduce

  1. Start a worker pool with a few task identifiers.
  2. Terminate the backend running the lookup's insert into graphile_worker._private_tasks (select pg_terminate_backend(pid) ...) while it runs.
  3. Add a job. It stays locked_by = null, attempts = 0 and due; the log shows only debug-level getJob errors (about 170 in 10 s).

Adding 0–40 ms of random delay to pool checkout makes this happen in roughly 1 in 4 starts under a terminated connection.

Suggested fix

Clear the cache when the lookup rejects, so the next poll retries it:

cache.lastDigest.catch(() => {
  if (cache.lastStr === str) cache.lastStr = '';
});

We run this as a local patch and the runner recovers on the next poll. It may also be worth logging repeated getJob failures above debug level.

Lingua principale
TypeScript
Stelle
2.5k
Fork
134
Merge medio
16h 24m
PR unite (30g)
3

Preparare l'ambiente

  • Include un Dockerfile o un file Docker Compose
  • Nessun modello di pull request
  • Nessuna guida per i contributori

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.

Altre issue di graphile/worker

Tutte le issue di graphile/worker

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.