fix(upload): set duplex for stream retry bodies#2902
Merged
Conversation
Contributor
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the upload retry helper to automatically set duplex: 'half' when a retry attempt uses a Node stream request body, addressing undici’s requirement for stream request bodies and adding a regression test intended to exercise real undici behavior.
Changes:
- Add stream-body detection and auto-inject
duplex: 'half'infetchWithRetry()when appropriate, while preserving caller-providedduplex. - Refactor stream-body detection into a helper for reuse within
fetchWithRetry(). - Add a Jest regression test that uses a local HTTP server to validate real undici stream-body behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/lib/client-file-uploader.ts |
Adds duplex: 'half' automatically for stream request bodies during retry attempts. |
__tests__/lib/fetch-with-retry-undici.js |
Introduces a regression test intended to validate undici’s duplex requirement with real stream bodies. |
23161e2 to
4ca2ef8
Compare
rinatkhaziev
approved these changes
Jun 22, 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.



Summary
duplex: 'half'automatically infetchWithRetrywhen an attempt uses a Node stream request bodyduplexvalues and keeps the one-shot stream retry guard from PR Fix file upload retry reusing an already-consumed stream body #2897undici.fetchwith the repo'sMockAgenttest helper, so stream-body validation is exercised instead of mockedWhy
Follow-up from the v4.0.6 upload fix: a customer upgraded from the original
Response body object should not be disturbed or lockedfailure and then hit:PR #2897 correctly recreates stream bodies per retry, but the existing tests mock
undici.fetch; they verify body recreation without exercising undici's real requirement that stream request bodies includeduplex: 'half'.Testing
npm run jest -- __tests__/lib/fetch-with-retry-undici.js __tests__/lib/client-file-uploader.js --runInBand(ran all non-e2e suites: 56 passed / 593 tests)npm run check-typesnpm run cmd:lint -- src/lib/client-file-uploader.ts __tests__/lib/fetch-with-retry-undici.jsnpm run build