← Back to PRs

#11101: fix: handle AbortError and WebSocket 1006 in unhandled rejection handler

by Nipurn123 open 2026-02-07 11:54 View on GitHub →
channel: line extensions: memory-lancedb agents stale
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