Skip to content

fix(fetch): preserve error code in decompression pipeline for retry logic#40946

Open
SebTardif wants to merge 1 commit into
microsoft:mainfrom
SebTardif:fix-fetch-retry-compressed
Open

fix(fetch): preserve error code in decompression pipeline for retry logic#40946
SebTardif wants to merge 1 commit into
microsoft:mainfrom
SebTardif:fix-fetch-retry-compressed

Conversation

@SebTardif
Copy link
Copy Markdown
Contributor

What this PR does

Fixes maxRetries being silently broken for compressed HTTP responses.

In packages/playwright-core/src/server/fetch.ts, the decompression pipeline error callback wraps all errors in new Error(...), destroying the .code property. The retry logic in _sendRequestWithRetries checks e.code !== 'ECONNRESET' to decide whether to retry. Since the wrapped error has no .code, retries never happen for compressed responses (the vast majority of real-world HTTP traffic, since accept-encoding: gzip,deflate,br is sent by default).

Fix: Added isNetworkConnectionError() helper that checks for ECONNRESET, EPIPE, ECONNABORTED. Network errors are passed through unwrapped to preserve .code; only actual decompression failures get wrapped.

AI Disclosure

Developed with AI assistance (Grok by xAI) in a human-in-the-loop workflow. All code reviewed and verified by the human author.

@dgozman dgozman requested a review from yury-s May 22, 2026 09:49
Copy link
Copy Markdown
Member

@yury-s yury-s left a comment

Choose a reason for hiding this comment

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

The change looks good, but please add a test.

…ogic

When a compressed HTTP response (gzip/br/deflate) encounters a network
error like ECONNRESET during body streaming, the pipeline error callback
and body error handler were wrapping the original error in a new Error,
destroying the .code property. The retry logic in _sendRequestWithRetries
checks e.code !== 'ECONNRESET' to decide whether to retry, so retries
never happened for compressed responses.

Fix: check if the error is a network error (ECONNRESET, EPIPE,
ECONNABORTED) and pass it through unwrapped so the retry logic can see
the code. Only wrap non-network errors as decompression failures.
@SebTardif SebTardif force-pushed the fix-fetch-retry-compressed branch from ec419c9 to 7de5f9e Compare May 22, 2026 21:21
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.

2 participants