Repository navigation
[CB-0] [sdk-superfan] Apply the request timeout to reading the body - #246
Draft
spicysouvlaki wants to merge 1 commit into
Draft
spicysouvlaki wants to merge 1 commit into
spicysouvlaki wants to merge 1 commit into
Conversation
fetchWithTimeout() clears its timer as soon as fetch() resolves with
headers. defaultParseResponse() then reads response.json()/text() with no
timer, so a server that sends headers and stalls leaves the promise pending
forever, despite the documented timeout and APIConnectionTimeoutError.
defaultParseResponse() now arms the same timeout on the request's controller
while it reads the body and maps that abort to APIConnectionTimeoutError
(a caller abort still surfaces as before). The timeout is passed through the
internal APIResponseProps.
Scope: the body gets its own timeout window (like a read timeout), not the
remainder of the header budget. Raw responses (__binaryResponse,
asResponse()) are untouched, so long downloads the caller streams are not
cut off by the request timeout.
Measured: new test serves headers plus '{' and stalls, timeout 50 ms. On main
it hits the 5 s jest timeout under native fetch and node-fetch; with this
change both reject with APIConnectionTimeoutError in ~60 ms.
src/core.ts is generated; this edit is sealed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
What happened
#206: when a server sends headers and then stalls, the request never times out (
still pending, not APIConnectionTimeoutError).Why
fetchWithTimeout()clears its timer once the headers arrive.defaultParseResponse()then reads the body with no timer running.Fix
defaultParseResponse()arms the request timeout on the request's controller while it reads JSON or text. An abort from that timer becomesAPIConnectionTimeoutError. Raw responses (asResponse(), binary) are unchanged, so downloads the caller streams are not cut off.Tests
{, then a stall, withtimeout: 50. Main hits the 5 s jest timeout under native fetch and node-fetch. This branch rejects withAPIConnectionTimeoutErrorin about 60 ms under both../scripts/lint,./scripts/test(203 passed),./scripts/buildall pass.Risk and rollout
src/core.tsis generated, so this is a sealed edit. The body gets its own timeout window, so the worst case is about 2×timeoutand not the remainder of the first one. It ships with the next SDK release.Fixes #206
🤖 Generated with Claude Code