Commit c1ffe9f
Harden Metro bundle retry against file-watcher races (#56530)
Summary:
Pull Request resolved: #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
fbshipit-source-id: 805ef9bc6e58fce7c1dc10d0cbbb7fdfa1fa24a51 parent 0f9b8e4 commit c1ffe9f
1 file changed
Lines changed: 93 additions & 41 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | 28 | | |
| 29 | + | |
32 | 30 | | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
| 31 | + | |
40 | 32 | | |
41 | | - | |
42 | | - | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
43 | 42 | | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
44 | 79 | | |
45 | | - | |
46 | | - | |
47 | | - | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
48 | 88 | | |
49 | 89 | | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
55 | 93 | | |
56 | | - | |
57 | | - | |
58 | | - | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
59 | 97 | | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
| 98 | + | |
| 99 | + | |
67 | 100 | | |
68 | | - | |
69 | | - | |
70 | 101 | | |
71 | 102 | | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
| 103 | + | |
| 104 | + | |
76 | 105 | | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
77 | 114 | | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | 115 | | |
82 | | - | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
83 | 123 | | |
84 | | - | |
| 124 | + | |
85 | 125 | | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
86 | 138 | | |
87 | 139 | | |
88 | 140 | | |
| |||
0 commit comments