fix(upload): harden fetch upload streams#2905
Merged
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 improves the error surfaced when fetchWithRetry exhausts retries by preserving low-level Undici fetch failure details (via the underlying cause) while still avoiding request/presigned URL details. It also adds regression coverage to ensure the new error message and cause chain are maintained.
Changes:
- Wrap the final exhausted-retries error to append an underlying
causemessage (when present) and preserve the original error ascause. - Add a Jest regression test covering
TypeError: fetch failedwith an underlyingwrite ECONNRESETcause.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/lib/client-file-uploader.ts | Adds withCauseMessage() and uses it when retries are exhausted to preserve actionable fetch cause details. |
| tests/lib/client-file-uploader.js | Adds regression test ensuring the final error message includes the underlying cause and preserves the original error via cause. |
cddbba6 to
f25e1ef
Compare
f25e1ef to
af1e5a5
Compare
af1e5a5 to
424e862
Compare
|
7 tasks
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
PassThrough/datalisteners withTransformstreams that count bytes while forwarding them toundici.fetchExpectheader before dispatching requests throughundici.fetchfetchcause details whenfetchWithRetryexhausts retriesContent-LengthbytesTypeError: fetch failedwith an underlyingwrite ECONNRESETcauseExpect: 100-continueheadersWhy
Follow-up from PLTFRM-2491 / the custom deploy incident thread. After v4.0.7, the customer no longer sees the disturbed-stream or missing-
duplexerrors, but later debug traces exposed two more local undici failure modes:and on the single-PUT path:
undici.fetchcannot send theExpectheader, so leaving that header in presigned options guarantees a local failure before the request reaches S3.For the content-length mismatch, the upload body was piped through a
PassThroughwith adatalistener for progress. That can put the stream into flowing mode before undici attaches its reader, allowing progress accounting to consume bytes that are no longer delivered to fetch. Using aTransformkeeps progress accounting in the same stream pipeline as the upload body and preserves backpressure/byte delivery.If future retries still exhaust with a lower-level transport cause, the final error becomes more actionable, e.g.
fetch failed: write ECONNRESET, without including presigned URLs or other request details.Testing
npm run jest -- __tests__/lib/client-file-uploader.js __tests__/lib/fetch-with-retry-undici.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/client-file-uploader.jsnpm run build