Harden Metro bundle retry against file-watcher races (#56530)#56530
Closed
rubennorte wants to merge 1 commit into
Closed
Harden Metro bundle retry against file-watcher races (#56530)#56530rubennorte wants to merge 1 commit into
rubennorte wants to merge 1 commit into
Conversation
|
@rubennorte has exported this pull request. If you are a Meta employee, you can view the originating Diff in D101791796. |
ac43189 to
325c1f8
Compare
rubennorte
added a commit
to rubennorte/react-native
that referenced
this pull request
Apr 21, 2026
Summary:
Each Fantom test writes a unique `\-<test>.js` entrypoint into
`.out/js-builds/` and then asks Metro to bundle it. Metro's file watcher
(metro-file-map's `FallbackWatcher` on Linux, debounced 100 ms) does not
always observe the new entrypoint by the time the HTTP request arrives,
especially when multiple workers are writing entrypoints concurrently.
The previous retry logic was too narrow:
- Only HTTP 404 was treated as retryable. Metro returns 404 only when the
entry file path itself can't be resolved; an unresolved transitive
dep (e.g. `setUpDefaultReactNativeEnvironment`) returns HTTP 500 with
`{type: 'UnableToResolveError'}` — we'd throw immediately on that.
- Only 3 attempts with a flat 500 ms wait (~1 s total), which is not
enough on a busy host with 8 workers writing entrypoints at once.
This results in ~30 spurious "Failed to request bundle from Metro: Unable
to resolve module ..." failures per run.
Refactor `createBundle` into a focused `fetchBundleWithRetry` helper that:
- Parses Metro's JSON error envelope (`{type, message, ...}` from
`formatBundlingError`) once per response and uses `type` to decide
whether to retry. Retries on HTTP 404, on HTTP 500 with
`UnableToResolveError` or `ResourceNotFoundError`, and on transient
`fetch` network errors. All other failures (transform errors, syntax
errors, real config issues) throw immediately so we don't waste seconds
on them.
- Uses exponential backoff (100 ms → 200 → 400 → 800 → 1.6 s, capped at
2 s) with up to 10 attempts (~11 s total worst case).
- Surfaces a clean error message (parsed from the JSON envelope) when
retries are exhausted.
Changelog: [Internal]
Differential Revision: D101791796
Summary: Pull Request resolved: react#56530 Each Fantom test writes a unique `\-<test>.js` entrypoint into `.out/js-builds/` and then asks Metro to bundle it. Metro's file watcher (metro-file-map's `FallbackWatcher` on Linux, debounced 100 ms) does not always observe the new entrypoint by the time the HTTP request arrives, especially when multiple workers are writing entrypoints concurrently. The previous retry logic was too narrow: - Only HTTP 404 was treated as retryable. Metro returns 404 only when the entry file path itself can't be resolved; an unresolved transitive dep (e.g. `setUpDefaultReactNativeEnvironment`) returns HTTP 500 with `{type: 'UnableToResolveError'}` — we'd throw immediately on that. - Only 3 attempts with a flat 500 ms wait (~1 s total), which is not enough on a busy host with 8 workers writing entrypoints at once. This results in ~30 spurious "Failed to request bundle from Metro: Unable to resolve module ..." failures per run. Refactor `createBundle` into a focused `fetchBundleWithRetry` helper that: - Parses Metro's JSON error envelope (`{type, message, ...}` from `formatBundlingError`) once per response and uses `type` to decide whether to retry. Retries on HTTP 404, on HTTP 500 with `UnableToResolveError` or `ResourceNotFoundError`, and on transient `fetch` network errors. All other failures (transform errors, syntax errors, real config issues) throw immediately so we don't waste seconds on them. - Uses exponential backoff (100 ms → 200 → 400 → 800 → 1.6 s, capped at 2 s) with up to 10 attempts (~11 s total worst case). - Surfaces a clean error message (parsed from the JSON envelope) when retries are exhausted. Changelog: [Internal] Reviewed By: andrewdacenko Differential Revision: D101791796
325c1f8 to
d38e529
Compare
|
This pull request has been merged in c1ffe9f. |
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:
Each Fantom test writes a unique
\-<test>.jsentrypoint into.out/js-builds/and then asks Metro to bundle it. Metro's file watcher(metro-file-map's
FallbackWatcheron Linux, debounced 100 ms) does notalways observe the new entrypoint by the time the HTTP request arrives,
especially when multiple workers are writing entrypoints concurrently.
The previous retry logic was too narrow:
entry file path itself can't be resolved; an unresolved transitive
dep (e.g.
setUpDefaultReactNativeEnvironment) returns HTTP 500 with{type: 'UnableToResolveError'}— we'd throw immediately on that.enough on a busy host with 8 workers writing entrypoints at once.
This results in ~30 spurious "Failed to request bundle from Metro: Unable
to resolve module ..." failures per run.
Refactor
createBundleinto a focusedfetchBundleWithRetryhelper that:{type, message, ...}fromformatBundlingError) once per response and usestypeto decidewhether to retry. Retries on HTTP 404, on HTTP 500 with
UnableToResolveErrororResourceNotFoundError, and on transientfetchnetwork errors. All other failures (transform errors, syntaxerrors, real config issues) throw immediately so we don't waste seconds
on them.
2 s) with up to 10 attempts (~11 s total worst case).
retries are exhausted.
Changelog: [Internal]
Reviewed By: andrewdacenko
Differential Revision: D101791796