From 0c153e2971db6edc9cdf363c93072488131a4340 Mon Sep 17 00:00:00 2001 From: Shubham Kumar Savita Date: Mon, 27 Apr 2026 23:21:43 -0700 Subject: [PATCH] Handle OutOfMemoryError in NetworkingModule response processing (#56630) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/56630 Catch `OutOfMemoryError` in the `onResponse` callback's response processing try-catch block in `NetworkingModule.kt`. Previously, only `IOException` was caught — `OutOfMemoryError` (which extends `Error`, not `Exception`) would propagate uncaught and crash the app. When the Java heap is near its limit (e.g., 256MB with <1% free), any allocation during response processing (buffer creation in `readWithProgress`, `responseBody.bytes()`, `responseBody.string()`) can trigger OOM. The fix converts this to a network request error event sent to JS, allowing the app to handle the failure gracefully (retry, show error message) instead of crashing. **Crash:** `android_crash:java.lang.OutOfMemoryError:com.oculus.igvr` **MID:** `024a57cfb70eef9a61af42d845c981a1` — 246 crashes in 7 days **Task:** T212267841 Logview link: [024a57cfb70eef9a61af42d845c981a1](https://www.internalfb.com/logview/system_vros_crashes/024a57cfb70eef9a61af42d845c981a1) Changelog: [Android][Fixed] - Catch OutOfMemoryError in NetworkingModule response processing to prevent app crashes Reviewed By: cortinico Differential Revision: D102236869 fbshipit-source-id: de6624640b3f2343ca8e516fe7677eecae23a932 --- .../facebook/react/modules/network/NetworkingModule.kt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/network/NetworkingModule.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/network/NetworkingModule.kt index 533a463bef7..c7f5b85b822 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/network/NetworkingModule.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/network/NetworkingModule.kt @@ -773,6 +773,14 @@ public class NetworkingModule( e.message, e, ) + } catch (e: OutOfMemoryError) { + NetworkEventUtil.onRequestError( + reactApplicationContext, + requestId, + devToolsRequestId, + "Out of memory while processing network response", + null, + ) } } }