fix(web-api): retry responses interrupted while reading the body - #2739
Open
ujjawal-yadav wants to merge 1 commit into
Open
fix(web-api): retry responses interrupted while reading the body#2739ujjawal-yadav wants to merge 1 commit into
ujjawal-yadav wants to merge 1 commit into
Conversation
`makeRequest` wraps `fetch` in `pRetry`, but `fetch` resolves as soon as the response headers arrive. The body was read by `buildResult` (and by `postFileUploadsToExternalURL`) after `makeRequest` had already returned, so a connection dropped partway through the body landed outside both the retry loop and the `catch` that converts failures into `WebAPIRequestError`. Callers saw a raw `TypeError: terminated` with an undefined `code`, and no retry was attempted. Read the body inside the retried task instead, returning a `FetchResponse` that replays the buffered bytes so both call sites keep consuming it as before. This restores the v7 behaviour, where the body was buffered before the request promise settled. Closes slackapi#2738
🦋 Changeset detectedLatest commit: e134198 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
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.
Summary
Fixes #2738.
makeRequest()wrapsfetchinpRetry, butfetchresolves once the response headers arrive. The body was read afterwards bybuildResult()— and bypostFileUploadsToExternalURL()— outside both the retry loop and thecatchthat produces a codedWebAPIRequestError. A connection dropped mid-body therefore neither retried nor got anerror.code. Under axios the body was materialized inside the retried request, so v7 retried the same interruption.The fix reads the body inside the retried task and returns a
FetchResponsethat replays the buffered bytes, so both call sites consume it unchanged. Same shape as thebufferingFetchworkaround in the issue, moved insidemakeRequestso it also covers a customfetch.Notes
Two side effects of the wider task boundary. Both match v7, neither is fixed here — happy to add either if you want it:
maxRequestConcurrency: 4, 200ms bodies): ~322ms on 8.1.1, ~561ms here, ~323ms if the body read moves just outside the queue callback.retries: 10: 1 request on 8.1.1, 11 here, 2 with a separate one-retry budget for interrupted bodies. Since fix(webhook): do not retry after a successful trigger delivery #2674 narrowedwebhookrecently, capping this seemed like your call rather than mine.Validation
npm test --workspace=@slack/web-api— 155 passing, including 3 new tests that all fail onmainnpm test --workspaces— 310 passingnpm run lint,npm run build,npm run docs— cleanRequirements