fix: isolate cold-start prefetch from main URLSession (iOS) + Android cookie/outcome#80
Open
oferRounds wants to merge 1 commit into
Open
Conversation
Use a dedicated URLSession for native autoprefetch so slow prefetch work cannot saturate the main session connection pool or block JS-initiated fetches. Skip awaiting an in-flight prefetch on the hot path; issue a fresh request on the main session instead while prefetch completes in the background. Also: validate autoprefetch URLs, apply default request/prefetch timeouts on iOS, persist last token-refresh outcome for debugging on Android, attach/store cookies for Cronet on Android, and export getFetchTokenRefreshLastOutcome from JS. Ported from HiBob production patch (react-native-nitro-fetch 1.0.0); FetchCache eviction barrier fix omitted here because it is already on main. Made-with: Cursor
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 / motivation
On cold start, native autoprefetch (token refresh + queued URLs) and JS-initiated
fetchcan compete for the same resources. We saw real-world symptoms in a large React Native app:URLSessionfor both autoprefetch and normal traffic meant long-running or stuck prefetch work could saturate the connection pool or otherwise interfere with interactive fetches.CookieManagerwere not consistently attached or updated from responses, so cold-start prefetch and follow-up requests could disagree on auth state.This PR addresses those gaps: isolate prefetch on iOS, stop blocking the hot path on pending prefetch, harden URLs and timeouts, improve Android cookie parity, and expose a small debug hook on JS.
Summary
Production-hardening ported from a downstream consumer that currently ships the same logic via
patch-packageonreact-native-nitro-fetch@1.0.0. Ported ontomargelo/main; theFetchCachebarrier eviction hunk from that patch was omitted here becausemainalready contains that fix.iOS
prefetchSession(URLSession) for native autoprefetch so prefetch traffic does not share the main session’s connection pool with JS-initiated fetches.timeoutMsand for autoprefetch.URL(string:)before enqueueing.Android
Cookieheader fromCookieManagerwhen building Cronet requests (when not already present); storeSet-Cookieon redirects and success.JS
getFetchTokenRefreshLastOutcome()(reads the same storage key Android/iOS write).Testing
Refs: downstream patch derived from production cold-start / app-loader investigation.
Made with Cursor