Skip to content

Fix data race on response body buffers in RCTInspectorNetworkReporter - #60187

Draft
huntie wants to merge 1 commit into
mainfrom
pr60187
Draft

huntie wants to merge 1 commit into
mainfrom
pr60187

Conversation

@huntie

@huntie huntie commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

RCTInspectorNetworkReporter buffers incremental text response bodies in a global NSMutableDictionary with no lock. RCTNetworking only reaches it from one serial queue, but the class is public, and a second reporter calling reportResponseEnd from another queue, as Expo's does from its URLSession delegate, mutates the dictionary while RCTNetworking appends to it.

Changes

  • Guard every responseBuffers access with one std::mutex.
  • Flush to storeResponseBody after releasing the lock, so it never nests with NetworkReporter's own locks.
  • Debug only: everything sits inside REACT_NATIVE_DEBUGGER_ENABLED, so release builds are unchanged.

Changelog:
[iOS][Fixed] - React Native DevTools: Fix a data race when another reporter ends a request while RCTNetworking buffers a response body

Test Plan

Built an Expo app on React Native 0.89.0-rc.0, whose copy of this file is identical to main, from source with Thread Sanitizer, on an iPhone simulator (iOS 27.2). A local server streamed 40 chunked text lines per response; each round sent 60 XHR text requests through RCTNetworking and 60 expo/fetch requests at once, with the Network domain enabled over CDP.

  • ✅ lldb on the unpatched build: maybeStoreResponseBodyIncremental and RCTNetworking's reportResponseEnd ran on com.meta.react.turbomodulemanager.queue, while Expo's reportResponseEnd ran on com.apple.NSURLSession-delegate, so the race is reachable.
  • ✅ Patched build, 5 rounds (600 requests): no crash, and Network.getResponseBody returned all 40 lines for 300 of 300 XHR and 300 of 300 expo/fetch requests.
  • Thread Sanitizer reported nothing before or after; the conflicting accesses are inside uninstrumented Foundation, so it cannot see this race. A crash before the fix did not reproduce in 5 rounds.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 20, 2026
@huntie
huntie added this pull request to stack #60189 November 20, 2026 17:36
@huntie
huntie removed this pull request from stack #60189 November 20, 2026 18:17
@github-actions

Copy link
Copy Markdown

Visual regression

No visual differences at 094d0726d2b0.

android: no capture

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. p: Expo Partner: Expo Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant