Skip to content

fix(upload): set duplex for stream retry bodies#2902

Merged
sjinks merged 1 commit into
trunkfrom
fix/upload-retry-duplex-stream-body
Jun 22, 2026
Merged

fix(upload): set duplex for stream retry bodies#2902
sjinks merged 1 commit into
trunkfrom
fix/upload-retry-duplex-stream-body

Conversation

@sjinks

@sjinks sjinks commented Jun 22, 2026

Copy link
Copy Markdown
Member

Summary

  • adds duplex: 'half' automatically in fetchWithRetry when an attempt uses a Node stream request body
  • preserves caller-provided duplex values and keeps the one-shot stream retry guard from PR Fix file upload retry reusing an already-consumed stream body #2897
  • adds a regression test that uses real undici.fetch with the repo's MockAgent test helper, so stream-body validation is exercised instead of mocked

Why

Follow-up from the v4.0.6 upload fix: a customer upgraded from the original Response body object should not be disturbed or locked failure and then hit:

RequestInit: duplex option is required when sending a body

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 include duplex: '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-types
  • npm run cmd:lint -- src/lib/client-file-uploader.ts __tests__/lib/fetch-with-retry-undici.js
  • npm run build

Copilot AI review requested due to automatic review settings June 22, 2026 22:45
@github-actions

github-actions Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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' in fetchWithRetry() when appropriate, while preserving caller-provided duplex.
  • 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.

Comment thread __tests__/lib/fetch-with-retry-undici.js Outdated
@sjinks sjinks force-pushed the fix/upload-retry-duplex-stream-body branch from 23161e2 to 4ca2ef8 Compare June 22, 2026 22:48
@sjinks sjinks self-assigned this Jun 22, 2026
@sjinks sjinks merged commit df0006d into trunk Jun 22, 2026
18 of 19 checks passed
@sjinks sjinks deleted the fix/upload-retry-duplex-stream-body branch June 22, 2026 23:00
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants