[iOS] Crash "attempt to insert nil object from objects[3]" in RCTNetworking handlers provider when a request runs after reload (BlobModule is nil)
Maintainers usually reply within 2 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 66/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- ios, objective-c, react-native
- Domain
- mobile
Research direction
Start with the default handlers provider in packages/react-native/Libraries/AppDelegate/RCTAppSetupUtils.mm and the handler lookup in packages/react-native/Libraries/Network/RCTNetworking.mm; read how the provider handles absent modules. Reproduce with the supplied reload and multipart request loop, then run the relevant iOS networking tests. Done when a request queued during reload no longer crashes if BlobModule is unavailable, while normal Blob URL handling still works.
Written by the indexing model from the issue text.
Description
Description
On iOS (New Architecture, bridgeless), the app can crash during a host reload with:
NSInvalidArgumentException: -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[3]
objects[3] is BlobModule in the default RCTNetworking handlers provider (RCTAppSetupUtils.mm:87):
return [@[
[RCTHTTPRequestHandler new],
[RCTDataRequestHandler new],
[RCTFileRequestHandler new],
[moduleRegistry moduleForName:"BlobModule"],
] arrayByAddingObjectsFromArray:URLRequestHandlerModules];
What happens:
- A reload (in our case
RCTTriggerReloadCommandListenersfrom a CodePush restart →RCTHost _reloadWithShouldRestartSurfaces) invalidates the oldRCTNetworking, which sets_handlers = nil(RCTNetworking.mm:204), and the oldRCTTurboModuleManager. Once_invalidatingis set,moduleForName:returns nil (RCTTurboModuleManager.mm:910). - A request that was already queued on the old networking method queue still runs afterwards.
prioritizedHandlerssees_handlers == niland calls the provider again. - The provider asks the dead registry for BlobModule, gets nil, and the array literal throws.
extractModuleConformingToProtocol in the same file already tolerates nil modules; only the BlobModule literal does not.
The code is unchanged in v0.88.1 and on main. We see it in production on 0.83.4 (about 85 crash events from 55 users over 5 months).
Proposed fix (we ship this as a local patch and it removes the crash in our repro):
NSMutableArray<id<RCTURLRequestHandler>> *handlers = [NSMutableArray
arrayWithObjects:[RCTHTTPRequestHandler new], [RCTDataRequestHandler new], [RCTFileRequestHandler new], nil];
id<RCTURLRequestHandler> blobModule = [moduleRegistry moduleForName:"BlobModule"];
if (blobModule != nil) {
[handlers addObject:blobModule];
} else {
RCTLogWarn(@"RCTNetworking: BlobModule is nil; blob URLs have no handler");
}
[handlers addObjectsFromArray:URLRequestHandlerModules];
return handlers;
Steps to reproduce
It is a race, so it needs a loop:
- Release build on the iOS simulator, New Architecture on (default).
- In JS, keep sending multipart
fetchrequests whose FormData has a part with auri(for exampledata:text/plain;base64,...). This starts a nestedRCTNetworkTask, which widens the window. Plain POSTs did not reproduce it for us in ~140 reloads. - Every ~2.5 s, trigger a host reload (we used
CodePush.restartApp(false); any trigger ofRCTTriggerReloadCommandListenersshould hit the same path, but I only tested CodePush). - Without the fix the app crashed after ~50 reloads (~150 s). With the fix: ~290 reloads, no crash.
React Native Version
0.83.4 (code unchanged in 0.88.1)
Affected Platforms
Runtime - iOS
Output of npx @react-native-community/cli info
react-native: 0.83.4
react: 19.2.4
Xcode: 27.2/27B52
iOS: hermesEnabled: true, newArchEnabled: true
Stacktrace or Logs
Crashed thread (RCTNetworking method queue):
-[__NSPlaceholderArray initWithObjects:count:]
+[NSArray arrayWithObjects:count:]
RCTAppSetupDefaultModuleFromClass block (RCTAppSetupUtils.mm) // handlers provider
-[RCTNetworking prioritizedHandlers]
-[RCTNetworking handlerForRequest:]
-[RCTNetworking networkTaskWithDevToolsRequestId:request:completionBlock:]
-[RCTNetworking sendRequest:callback:] block_invoke_2
Main thread at the same time:
-[CodePush loadBundle]
RCTTriggerReloadCommandListeners
-[RCTHost _reloadWithShouldRestartSurfaces:]
MANDATORY Reproducer
I can't share the app. The steps above reproduce it on a new-arch app with a JS loop and a reload trigger. I can build a minimal public reproducer if needed.
- Dominant language
- C++
- Stars
- 127k
- Forks
- 25.5k
- Avg merge
- 3d 22h
- Merged PRs (30d)
- 235
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from react/react-native
-
Needs: Author Feedback Needs: Repro
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
react/react-native#60059 · 1 comment ·
Maintainers usually reply within 2 days
-
Needs: Triage :mag:
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
react/react-native#60000 ·
Maintainers usually reply within 2 days
-
`yarn test-ios` exits before building RNTester: `objc-test.sh` launches the WebSocket server script #59433 deletedPossibly taken @lazerg claimed this 4 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
react/react-native#59939 ·
Maintainers usually reply within 2 days
-
iOS Fabric pointer-handler reset leaves the next lone touch non-primaryPossibly taken @alleneubank claimed this 6 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
react/react-native#59919 ·
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
react/react-native#59722 ·
Maintainers usually reply within 2 days
All issues in react/react-native
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
petercorke/robotics-toolbox-python#943 · 1 comment ·
Maintainers usually reply within 1 day
-
area:build bug
Difficulty 1/5 Under an hour Newbie friendliness 90/100
NatronGitHub/openfx-arena#71 ·
Maintainers usually reply within 1 day
-
upstream-blocked
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
ROCm/FastFlowLM#1057 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
NatronGitHub/openfx-gmic#45 ·
Maintainers usually reply within 1 day