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

Đang mở Phù hợp với người mới
#638 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

@agustin18 đang làm issue này rồi.

Từ ngày 23/11/2026.

  • #640 của @devtechedge — đã đóng, không merge
  • #656 của @agustin18 — đang mở

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
72/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
node.js, postgresql, typescript
Lĩnh vực
backend

Hướng nghiên cứu

Bắt đầu trong src/taskIdentifiers.ts: cache.lastStr và cache.lastDigest được đặt trước lookup bất đồng bộ và không bao giờ bị xóa khi nó bị reject, vì vậy getJobs chờ cùng một reject ở mỗi poll. Đọc logic cache đó cùng với lệnh gọi withPgClient.withRetries (chỉ retry 40001/40P01/57P03/EHOSTUNREACH/ETIMEDOUT) và log getJob ở mức debug trong worker.js. Tái hiện bằng cách kết thúc backend của lookup bằng pg_terminate_backend và thêm một job; done nghĩa là runner phục hồi ở poll tiếp theo, lý tưởng nhất là với các lỗi lặp lại được ghi log trên mức debug.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
TypeScript
Star
2.5k
Fork
134
Merge trung bình
16 giờ 24 phút
Pull request đã merge (30 ngày)
3

Chuẩn bị môi trường

  • Có Dockerfile hoặc tệp Docker Compose
  • Không có mẫu pull request
  • Không có hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của graphile/worker

Tất cả issue của graphile/worker

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.