fix: default timeout on outbound fetch calls - #91
Open
hugo-ccabral wants to merge 2 commits into
Open
Conversation
Mirrors decocms/blocks#392. Nothing bounded how long an outbound fetch could hang, letting a stuck upstream connection pin request context in memory until the runtime kills the isolate. Adds commerce/utils/fetchTimeout.ts (AbortSignal.timeout composed with any caller signal via AbortSignal.any, 10s default) and wires it into VTEX, Magento, Resend, Shopify, and the Google Fonts loader's raw fetch call sites. This repo pins @decocms/start@6.6.1, which predates the equivalent export in blocks, so the helper is duplicated here for now -- replace with a re-export from @decocms/start/sdk/fetchTimeout once that dependency is bumped past the version shipping it. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
…apper A future dev can still bypass fetchSafe/vtexFetch/magentoFetch/etc. by typing bare fetch(), silently losing the timeout. Adds a Biome noRestrictedGlobals override banning the fetch global in vtex/magento/resend/shopify/website (excluding client-side hooks and tests), pointing at the sanctioned client. The ban also catches `typeof fetch` in type positions, so introduces a FetchFn alias (commerce/utils/fetchTimeout.ts) to replace those annotations. Also fixes a real gap the rule caught: vtex/utils/sitemap.ts's fetchImpl defaulted to raw fetch, same unbounded-hang risk as the other call sites. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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
fetch()could hang — a stuck upstream connection (VTEX/CDN holding a TCP connection open) pins request context in memory until the runtime kills the isolate.commerce/utils/fetchTimeout.ts:withFetchTimeout()/withTimeoutSignal(), nativeAbortSignal.timeout()composed withAbortSignal.any()so a caller-supplied signal is never dropped. Default 10s._fetchfallback +fetchSafe/fetchAPI, Magento'smagentoFetch, Resend'ssendEmail, Shopify'screateGraphqlClientfallback, and the Google Fonts loader.@decocms/start@6.6.1, which predates the equivalent export inblocks, so the helper is duplicated locally for now. Once the dependency bumps past the version shippingsdk/fetchTimeout, replace this file with a re-export and delete the copy.Test plan
🤖 Generated with Claude Code
Summary by cubic
Add a default 10s timeout to all outbound
fetch()calls to stop hung upstreams from pinning request context. Ban barefetchto enforce the wrapper; the timeout helper is duplicated locally until@decocms/startexposes it.Bug Fixes
commerce/utils/fetchTimeout.tswithwithFetchTimeout()andwithTimeoutSignal()(10s default).fetchSafe, sitemap proxy), Magento (magentoFetch), Resend (sendEmail), Shopify (GraphQL client fallback), and the Google Fonts loader.AbortSignalin requests.Refactors
noRestrictedGlobalsrule to ban barefetchinvtex/**,magento/**,resend/**,shopify/**, andwebsite/**(excluding hooks/tests); use the wrapped clients orwithFetchTimeout.FetchFnalias and replacedtypeof fetchannotations to satisfy the lint rule.Written for commit cbf588e. Summary will update on new commits.