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

Abierto Apto para principiantes
#638 0 comentarios 0 reacciones 0 asignados Ver en GitHub

@agustin18 ya está trabajando en esto.

Desde el 23/11/2026.

  • #640 de @devtechedge — cerrado sin fusionar
  • #656 de @agustin18 — abierto

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
72/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
node.js, postgresql, typescript
Área
backend

Línea de trabajo

Empieza en src/taskIdentifiers.ts: cache.lastStr y cache.lastDigest se establecen antes del lookup asíncrono y nunca se limpian cuando este rechaza, así que getJobs espera el mismo rechazo en cada poll. Lee esa lógica de caché junto con la llamada withPgClient.withRetries (que solo reintenta 40001/40P01/57P03/EHOSTUNREACH/ETIMEDOUT) y el logging de getJob a nivel debug en worker.js. Reproduce terminando el backend del lookup con pg_terminate_backend y añadiendo un job; done significa que el runner se recupera en el siguiente poll, idealmente con fallos repetidos registrados por encima de debug.

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

Descripción

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.

Lenguaje dominante
TypeScript
Estrellas
2.5k
Forks
134
Merge medio
16 h 24 min
PR fusionados (30 d)
3

Preparar el entorno

  • Incluye un Dockerfile o un archivo de Docker Compose
  • Sin plantilla de pull request
  • Sin guía de contribución

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 graphile/worker

Todos los issues de graphile/worker

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.