Skip to content

Commit 26c3aef

Browse files
shubhamksavitafacebook-github-bot
authored andcommitted
Handle OutOfMemoryError in NetworkingModule response processing
Summary: 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
1 parent c20a58a commit 26c3aef

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

  • packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/network

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/network/NetworkingModule.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,14 @@ public class NetworkingModule(
773773
e.message,
774774
e,
775775
)
776+
} catch (e: OutOfMemoryError) {
777+
NetworkEventUtil.onRequestError(
778+
reactApplicationContext,
779+
requestId,
780+
devToolsRequestId,
781+
"Out of memory while processing network response",
782+
null,
783+
)
776784
}
777785
}
778786
}

0 commit comments

Comments
 (0)