fix: Handle connection drops (UND_ERR_SOCKET) and prevent process crash#377
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 |
🔒 Security Scan Results
⏱️ SLA Breach Summary
✅ BUILD PASSED - All security checks passed |
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