#11101: fix: handle AbortError and WebSocket 1006 in unhandled rejection handler
channel: line
extensions: memory-lancedb
agents
stale
Cluster:
Gateway Error Handling Improvements
This PR fixes the gateway crashes caused by unhandled promise rejections from Node.js fetch() calls reported in #11095.
## Changes
- **Added DOMException-style AbortError detection**: Now checks for `code: "ABORT_ERR"` or `code: "20"` (DOMException abort code), plus fallback string checks
- **Added WebSocket close code 1006 handling**: WebSocket abnormal closure is now treated as a transient network error
- **Added additional undici error codes**: `UND_ERR_ABORTED`, `UND_ERR_REQ_RETRY`, `UND_ERR_RESPONSE_STATUS_CODE`
- **Improved cross-realm error detection**: Better handling of plain objects with fetch failures
- **Added 6 comprehensive tests** for new edge cases
## Fixes
- **Crash 1** (`AbortError: This operation was aborted`): Caught by checking ABORT_ERR code or string pattern
- **Crash 2** (`TypeError: fetch failed`): Already handled, improved detection for edge cases
- **Crash 3** (WebSocket 1006 abnormal closure): Now explicitly handled as transient
The gateway will now log these as warnings and continue running instead of crashing.
Fixes #11095
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This change expands the unhandled-rejection suppression logic to treat additional fetch/undici abort and transient network failures as non-fatal. It adds broader AbortError detection (including DOMException-style codes and string fallbacks), adds WebSocket abnormal close code `1006` to the transient bucket, extends the undici transient code allowlist, and introduces new Vitest cases covering these edge scenarios.
The implementation lives in `src/infra/unhandled-rejections.ts`, which is the central classifier used by the process-level `unhandledRejection` handler to decide whether to warn-and-continue vs. exit.
<h3>Confidence Score: 3/5</h3>
- This PR is close to safe to merge, but it broadens transient-error classification in a way that can suppress real application errors.
- Core logic change is small and well-covered by tests, but the new `includes("fetch failed")` check can misclassify arbitrary thrown values as transient, changing behavior from an exact undici TypeError match and potentially hiding bugs.
- src/infra/unhandled-rejections.ts (transient error classification around `fetch failed`)
<!-- greptile_other_comments_section -->
<sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#10034: Don't crash gateway on transient unhandled fetch failures
by gigq · 2026-02-06
86.8%
#7558: fix: Handle Grammy/Telegram network errors to prevent gateway crashes
by kaigritun · 2026-02-03
81.8%
#7563: fix: expand transient network error detection
by kaigritun · 2026-02-03
81.4%
#12870: fix: recover from telegram fetch errors (issue #12835)
by ambicuity · 2026-02-09
81.2%
#12314: fix: treat HTTP 5xx server errors as failover-worthy
by hsssgdtc · 2026-02-09
80.0%
#19463: fix: suppress undici TLS setSession crash instead of exiting
by abbudjoe · 2026-02-17
79.9%
#4653: fix(gateway): improve crash resilience for mDNS and network errors
by AyedAlmudarra · 2026-01-30
79.8%
#4462: fix: prevent gateway crash when all auth profiles are in cooldown
by garnetlyx · 2026-01-30
79.0%
#17758: Fix crash on transient Discord gateway zombie connection errors
by DoyoDia · 2026-02-16
78.9%
#3831: fix: ignore mDNS socket errors to prevent gateway crashes
by cici1029 · 2026-01-29
78.5%