[iOS] Crash "attempt to insert nil object from objects[3]" in RCTNetworking handlers provider when a request runs after reload (BlobModule is nil)

オープン
#59,804 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 2 日以内に返信

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
66/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
ios, objective-c, react-native
領域
mobile

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

Needs: Author Feedback Needs: Repro
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:

  1. A reload (in our case RCTTriggerReloadCommandListeners from a CodePush restart → RCTHost _reloadWithShouldRestartSurfaces) invalidates the old RCTNetworking, which sets _handlers = nil (RCTNetworking.mm:204), and the old RCTTurboModuleManager. Once _invalidating is set, moduleForName: returns nil (RCTTurboModuleManager.mm:910).
  2. A request that was already queued on the old networking method queue still runs afterwards. prioritizedHandlers sees _handlers == nil and calls the provider again.
  3. 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:

  1. Release build on the iOS simulator, New Architecture on (default).
  2. In JS, keep sending multipart fetch requests whose FormData has a part with a uri (for example data:text/plain;base64,...). This starts a nested RCTNetworkTask, which widens the window. Plain POSTs did not reproduce it for us in ~140 reloads.
  3. Every ~2.5 s, trigger a host reload (we used CodePush.restartApp(false); any trigger of RCTTriggerReloadCommandListeners should hit the same path, but I only tested CodePush).
  4. 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.

主要言語
C++
スター
127k
フォーク
25.5k
平均マージ
3日 22時間
マージ済み PR(30日)
235

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

react/react-native のほかの issue

react/react-native の issue をすべて見る

似ている issue

C++ の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。