react-native: iOS: App crashes when BlobModule is nil during RCTNetworking initialization

Description

Problem Description

While the exact root cause remains unclear, we are intermittently encountering an NSInvalidArgumentException under the new architecture. The crash appears to originate from RCTAppSetupUtils.mm, where [moduleRegistry moduleForName:@“BlobModule”] unexpectedly returns nil.

Steps to reproduce

While we have not been able to reproduce the issue on our end, it has been consistently reported in Crashlytics. Interestingly, over 50% of the reported crashes are occurring on iPhone 7 Plus and iPhone 6 devices.

React Native Version

0.78.0

Affected Platforms

Runtime - iOS

Areas

Bridgeless - The New Initialization Flow

Output of npx @react-native-community/cli info

System:
  OS: macOS 15.1.1
  CPU: (10) x64 Apple M2 Pro
  Memory: 29.69 MB / 32.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 20.12.0
    path: ~/.nvm/versions/node/v20.12.0/bin/node
  Yarn:
    version: 3.6.4
    path: ~/projects/my-project/node_modules/.bin/yarn
  npm:
    version: 10.8.1
    path: ~/.nvm/versions/node/v20.12.0/bin/npm
  Watchman:
    version: 2024.04.22.00
    path: /usr/local/bin/watchman
Managers:
  CocoaPods:
    version: 1.16.2
    path: /Users/me/.rbenv/shims/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 24.1
      - iOS 18.1
      - macOS 15.1
      - tvOS 18.1
      - visionOS 2.1
      - watchOS 11.1
  Android SDK: Not Found
IDEs:
  Android Studio: 2024.3 AI-243.22562.218.2431.13114758
  Xcode:
    version: 16.1/16B40
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.13
    path: /Library/Java/JavaVirtualMachines/zulu-17.jdk/Contents/Home/bin/javac
  Ruby:
    version: 3.0.6
    path: /Users/me/.rbenv/shims/ruby
npmPackages:
  "@react-native-community/cli":
    installed: 15.0.1
    wanted: 15.0.1
  react:
    installed: 19.0.0
    wanted: 19.0.0
  react-native:
    installed: 0.78.0
    wanted: 0.78.0
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: true
  newArchEnabled: true

Stacktrace or Logs

Fatal Exception: NSInvalidArgumentException
0 CoreFoundation 0x92c60 exceptionPreprocess
1 libobjc.A.dylib 0x14ee4 objc_exception_throw
2 CoreFoundation 0x18d694 -[NSCFString characterAtIndex:].cold.1
3 CoreFoundation 0x18b0b8 -[NSPlaceholderArray initWithCapacity:].cold.1
4 CoreFoundation 0x1fd08 -[NSPlaceholderArray initWithObjects:count:]
5 CoreFoundation 0x4971c +[NSArray arrayWithObjects:count:]
6 React_RCTAppDelegate 0x4f6c RCTAppSetupDefaultModuleFromClass_block_invoke_2 + 103 (RCTAppSetupUtils.mm:103)
7 RCTNetwork 0x68d0 -[RCTNetworking prioritizedHandlers] + 278 (RCTNetworking.mm:278)
8 RCTNetwork 0x6718 -[RCTNetworking handlerForRequest:] + 229 (RCTNetworking.mm:229)
9 RCTNetwork 0x9cc8 -[RCTNetworking networkTaskWithRequest:completionBlock:] + 710 (RCTNetworking.mm:710)
10 RCTNetwork 0x8c8c -[RCTNetworking sendRequest:responseType:incrementalUpdates:responseSender:] + 662 (RCTNetworking.mm:662)
11 RCTNetwork 0xa464 38-[RCTNetworking sendRequest:callback:]block_invoke_2 + 761 (RCTNetworking.mm:761)



Collection element of type 'std::nullptr_t' is not an Objective-C object

Reproducer

sorry I have no Reproducer to provide

Screenshots and Videos

No response

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Comments: 19 (15 by maintainers)

Commits related to this issue

Most upvoted comments

@hoonjoo-park I think your idea is solid. The guide was thought for apps that have to integrate react native in one single screen. So when the screen is dismissed, it’s ok to destroy the ReactNativeDelegate.

If your app has multiple screens and you want to reuse the same delegate, that’s definitely a good solution. I would probably not use a singleton, but I believe that you have some sort of coordinator that pushes the various VC. I would rather have the coordinator be the ReactNativeDelegate or create and hold a refernece to the delegate, and then pass it around. This should made the code more testable and easier to maintain. But that’s a design decision on your side! 😉

Hi @cipolleschi, I’ve applied the patch from this PR and monitored the behavior for about a month, but unfortunately, the same issue is still occurring.

After checking the stack trace logs from firebase, it doesn’t seem like the user is rapidly and frequently opening and closing the React Native screen(module). It appears to crash when closing a specific RN module — the crash usually occurs within about 1 second after the exit event is triggered.

I’ll take a closer look at that particular RN module to see if there’s anything unusual, and I’ll follow up once I find something.

yeah, that PR might fix! The author is a colleague of mine that is working on the problem. Consider that the PR is not landed yet. You can try to apply it to your project.