fix(api): do not crash the process on the known undici socket-end assertion (BIT-31305) #7

Merged
spark merged 1 commits from task/BIT-31305-undici-socket-end-assertion-guard into main 2026-10-17 14:30:56 +01:00
Owner

Summary

  • BIT-31305 (Error Loop): the worker crashed once on node09 CT 264 with AssertionError [ERR_ASSERTION]: false == true at Parser.finish in Node's bundled undici — this is nodejs/undici#5360, an uncatchable assertion thrown from the socket end handler when the HTTP/1 parser is paused for backpressure while the remote socket ends.
  • pm2 already auto-restarted the worker within the same second (confirmed live: photoreport-worker-error-1.log on CT 264 ends exactly on this assertion, followed by a clean restart ~1h20m before investigation).
  • watchProcess() in apps/api/src/lib/reporter.ts was treating this as fatal like any other uncaught exception, killing the whole process (and any other in-flight work) over one already-closed connection.
  • This change recognizes the narrow ERR_ASSERTION + undici + Parser.finish/onHttpSocketEnd signature and reports it as a warning without exiting; every other uncaught exception still fails fast as before.

Test plan

  • pnpm vitest run test/reporter.test.ts — 5/5 pass (new test simulates the exact production stack trace, asserts process.exit is not called and the event is reported at warning level)
  • Confirmed pre-existing (unrelated) typecheck errors in apps/api are present on main too (stale @photoreport/metadata build output), not introduced by this change
## Summary - BIT-31305 (Error Loop): the worker crashed once on node09 CT 264 with `AssertionError [ERR_ASSERTION]: false == true` at `Parser.finish` in Node's bundled undici — this is [nodejs/undici#5360](https://github.com/nodejs/undici/issues/5360), an uncatchable assertion thrown from the socket end handler when the HTTP/1 parser is paused for backpressure while the remote socket ends. - `pm2` already auto-restarted the worker within the same second (confirmed live: `photoreport-worker-error-1.log` on CT 264 ends exactly on this assertion, followed by a clean restart ~1h20m before investigation). - `watchProcess()` in `apps/api/src/lib/reporter.ts` was treating this as fatal like any other uncaught exception, killing the whole process (and any other in-flight work) over one already-closed connection. - This change recognizes the narrow `ERR_ASSERTION` + `undici` + `Parser.finish`/`onHttpSocketEnd` signature and reports it as a warning without exiting; every other uncaught exception still fails fast as before. ## Test plan - [x] `pnpm vitest run test/reporter.test.ts` — 5/5 pass (new test simulates the exact production stack trace, asserts `process.exit` is not called and the event is reported at `warning` level) - [x] Confirmed pre-existing (unrelated) typecheck errors in `apps/api` are present on `main` too (stale `@photoreport/metadata` build output), not introduced by this change
spark added 1 commit 2026-10-17 14:24:57 +01:00
fix(api): do not crash the process on the known undici socket-end assertion
ci / rust (pull_request) Successful in 3m55s
ci / typescript (pull_request) Successful in 7m28s
6d37b9b541
A single-occurrence critical alert (BIT-31305) traced to node09 CT 264: the
worker crashed with AssertionError [ERR_ASSERTION]: false == true at
Parser.finish in Node's bundled undici. That is nodejs/undici#5360 -- the
HTTP/1 parser asserts !this.paused when the remote socket ends while the
parser is paused for backpressure, and throws uncatchably from the socket
end handler. pm2 already restarted the worker within the same second, but
watchProcess() was also killing the whole process (and losing any other
in-flight work) for this one already-closed connection.

Recognize the narrow ERR_ASSERTION + undici + Parser.finish signature in
watchProcess() and report it as a warning without exiting; every other
uncaught exception still fails fast as before.

Paperclip-Issue: BIT-31305
Paperclip-Run: 02f17eaf-2939-43e0-93b2-f6d047452558
paperclip-review-bot left a comment
Member

auto-approve: CI success (gitea_auto_approve_open_prs_once.py)

auto-approve: CI success (gitea_auto_approve_open_prs_once.py)
founding-engineer left a comment
Member

auto-approve: CI success (gitea_auto_approve_open_prs_once.py)

auto-approve: CI success (gitea_auto_approve_open_prs_once.py)
devops-engineer left a comment
Member

auto-approve: CI success (gitea_auto_approve_open_prs_once.py)

auto-approve: CI success (gitea_auto_approve_open_prs_once.py)
spark scheduled this pull request to auto merge when all checks succeed 2026-10-17 14:30:55 +01:00
spark merged commit 2190cecbd2 into main 2026-10-17 14:30:56 +01:00
Sign in to join this conversation.