fix: Handle connection drops (UND_ERR_SOCKET) and prevent process crash#377
Open
harshitha-cstk wants to merge 4 commits intodevelopmentfrom
Open
fix: Handle connection drops (UND_ERR_SOCKET) and prevent process crash#377harshitha-cstk wants to merge 4 commits intodevelopmentfrom
harshitha-cstk wants to merge 4 commits intodevelopmentfrom
Conversation
- Add .catch() on response.json() in 200 and non-200 branches to handle body-read failures - Retry on socket/abort errors (terminated, UND_ERR_SOCKET, UND_ERR_ABORTED) via onError() - Treat fetch-level and body-read socket errors consistently; reject with actual error when not retrying - Add SDK engineering investigation doc for UND_ERR_SOCKET handling Made-with: Cursor
🔒 Security Scan Results
⏱️ SLA Breach Summary
✅ BUILD PASSED - All security checks passed |
🔒 Security Scan Results
⏱️ SLA Breach Summary
✅ BUILD PASSED - All security checks passed |
🔒 Security Scan Results
⏱️ SLA Breach Summary
✅ BUILD PASSED - All security checks passed |
cs-raj
approved these changes
Mar 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When the remote server closes the TLS connection during a CDA request, Node 22's fetch (undici) can reject with
TypeError: terminatedandcause.code === 'UND_ERR_SOCKET'. In the SDK this led to:response.json()had no.catch(). If the connection closed during body read, that rejection was unhandled and could crash the Node process.Solution
.catch()on theresponse.json()promise in both the 200 and non-200 branches so body-read errors are handled and no longer cause unhandled rejections.message === 'terminated'anderror.cause.code === 'UND_ERR_SOCKET'or'UND_ERR_ABORTED'as retriable and, whenretryLimit > 0, use the existingonError()retry path.Changes
src/core/lib/request.js.catch()ondata.then(...)to handle body-read errors, detect socket/abort, retry viaonError(err)when possible, otherwisereject(err)..catch((err) => ...)ondata.then(...)with the same socket/abort detection and retry; reject witherror{ status, statusText }when not retrying.fetch(...).catch: detect socket/abort and callonError(error)whenretryLimit > 0, elsereject(error).docs/SDK-Engineering-Investigation-UND_ERR_SOCKET.md: Investigation doc for SDK engineering.Result
retryLimit/retryDelay/retryDelayOptions.error.cause.code) when retries are exhausted, so they can handle or log failures without process crash.Made with Cursor