fix(maticjs): disable HTTP keep-alive on metadata fetches to fix Premature close#484
Open
MaximusHaximus wants to merge 1 commit into
Open
fix(maticjs): disable HTTP keep-alive on metadata fetches to fix Premature close#484MaximusHaximus wants to merge 1 commit into
MaximusHaximus wants to merge 1 commit into
Conversation
…ature close node-fetch reuses keep-alive sockets (default since Node 19) that the upstream CDN has idle-closed; the next gzip response dies mid-decompression as `FetchError: Premature close`, mislabeled "network <net> - <ver> is not supported". Pass node-fetch a keepAlive:false agent for the network-config and ABI fetches (Node build only; window.fetch ignores it). webpack resolve.fallback maps http/https to empty stubs so the web/UMD bundles still build.
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. |
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.
Problem
@maticnetwork/maticjsloads network config + contract ABIs at runtime fromstatic.polygon.technologyvia node-fetch. Since Node 19 made HTTP keep-alive the default, node-fetch reuses a socket the CDN has idle-closed; the next gzip response dies mid-decompression asFetchError: Premature close, which surfaces as the misleadingnetwork <net> - <ver> is not supported. It reproduces 100% from datacenter/CI egress and intermittently elsewhere, and the retry added in #481 can't recover because every reused socket is already stale.Fix
Pass node-fetch a
keepAlive: falseagent for these fetches (Node build only —window.fetchignoresagent). They run once per client init and are cached, so a fresh connection per request only costs a TLS handshake at startup.webpack resolve.fallbackmapshttp/httpsto empty stubs so the web/UMD/standalone bundles still build (the browser branch never executes them).Evidence
Isolated in CI on the same runner that fails today (5 attempts each,
.../mainnet/v1/index.json): node-fetch default keep-alive 0/5;keepAlive:false5/5. curl + Node's built-in fetch (undici) reach origin 30/30, confirming it's the node-fetch keep-alive path, not a network/CDN block.Validation
pnpm --filter @maticnetwork/maticjstypecheck + build (all three webpack targets) + test (36 passing) green locally.