Unhandled rejection when recording a job's outcome fails with unbatched completeJob/failJob

未关闭
#641 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

@cpruijsen 已经在做这个了。

开始于 2026年10月12日。

  • #643 来自 @cpruijsen —— 未关闭
  • #645 来自 @ujjawal-yadav —— 未关闭

评估

难度
3/5
预计耗时
1-2 天
新手友好度
62/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
node.js, postgresql, typescript
领域
backend, databases

调研方向

Start with the unbatched completeJob and failJob in dist/main.js, around lines 879-921, and the call sites in dist/worker.js near lines 262 and 283, where the returned promise is neither awaited nor given a rejection handler. Check withRetries in dist/lib.js, which rethrows errors without a retryable code. Reproduce by wrapping the pool client so one update or delete query rejects, then confirm the rejection reaches unhandledRejection. Done means the failure is logged with the job id and/or reported via worker:fatalError, with no unhandled rejection.

由索引模型根据 Issue 内容生成。

描述

Summary

With the default (unbatched) completeJobBatchDelay / failJobBatchDelay of -1, the worker calls completeJob(job) and failJob(...) without awaiting them or attaching a rejection handler. If the query that records the job's outcome fails with an error that withRetries does not consider retryable, for example Error: Connection terminated unexpectedly from pg (which has no code), the rejection is unhandled. In a Node process without an unhandledRejection listener this crashes the process, and in every case worker:fatalError is not emitted and the job stays locked until its lock expires.

Steps to reproduce
  1. Run a worker with run() and the default batch delays (-1), using a pg.Pool with an error handler attached.
  2. Make the connection drop (or the query reject with an error without a retryable code) on the query that records a job's outcome: the update ... _private_jobs ... set last_error ... of a failing task, or the delete from ... _private_jobs ... of a succeeding one. Wrapping the pool's client so that query rejects once with new Error("Connection terminated unexpectedly") reproduces it deterministically.
  3. Add a job for a task (one that throws, for the failJob path; one that succeeds, for the completeJob path) and let the worker pick it up.
Expected results

The failure to record the outcome is handled: logged with the job id (as the batched path's error handler does) and/or reported through worker:fatalError or another event, without leaving a rejected promise unhandled.

Actual results

The rejection reaches process.on("unhandledRejection"). Without a listener, Node exits with the error. No worker:fatalError event is emitted, nothing is logged by the worker, and the job remains locked until the stale-lock reset releases it.

Additional context
  • graphile-worker 0.18.0, Node 24.21, pg 8.23, PostgreSQL 18.
  • In the published dist/worker.js, failJob({...}) (around line 262) and completeJob(job) (around line 283) are called inside a try whose catch (fatalError) only sees synchronous throws, so a rejected promise bypasses it.
  • In dist/main.js (around lines 879-921), the unbatched completeJob / failJob are plain closures over batchCompleteJobs / batchFailJobs with withPgClient.withRetries and no error callback; only the batched branch passes an error handler.
  • withRetries (dist/lib.js, around lines 365-385) retries only errors whose code is in RETRYABLE_ERROR_CODES, so a connection-terminated error without a code is rethrown immediately.
  • I searched existing issues and found nothing about this; #635 and #636 are related but concern the batched path and runner.promise.
Possible Solution

Handle the promise returned by the unbatched completeJob / failJob in the worker, for example by attaching a rejection handler that logs the error with the job id and emits worker:fatalError (or a dedicated event), matching how the batched path reports its failures. A local patch doing completeJob(job)?.then(null, (fatalError) => logger.error(..., { fatalError })) (and the same for failJob) removes the unhandled rejection in our testing.

主要语言
TypeScript
星标
2.5k
派生
134
平均合并
16 小时 24 分钟
30 天内合并 PR
3

环境准备

  • 提供 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 没有贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

graphile/worker 的其他 Issue

查看 graphile/worker 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。