Skip to content

Handle OutOfMemoryError in NetworkingModule response processing#56630

Closed
shubhamksavita wants to merge 1 commit intofacebook:mainfrom
shubhamksavita:export-D102236869
Closed

Handle OutOfMemoryError in NetworkingModule response processing#56630
shubhamksavita wants to merge 1 commit intofacebook:mainfrom
shubhamksavita:export-D102236869

Conversation

@shubhamksavita
Copy link
Copy Markdown
Contributor

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
Changelog: [Android][Fixed] - Catch OutOfMemoryError in NetworkingModule response processing to prevent app crashes

Reviewed By: cortinico

Differential Revision: D102236869

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
@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 Apr 28, 2026
@meta-codesync
Copy link
Copy Markdown

meta-codesync Bot commented Apr 28, 2026

@shubhamksavita has exported this pull request. If you are a Meta employee, you can view the originating Diff in D102236869.

Copy link
Copy Markdown
Contributor

@cortinico cortinico left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review automatically exported from Phabricator review in Meta.

@meta-codesync meta-codesync Bot closed this in 0c153e2 Apr 28, 2026
@react-native-bot
Copy link
Copy Markdown
Collaborator

This pull request was successfully merged by @shubhamksavita in 0c153e2

When will my fix make it into a release? | How to file a pick request?

@react-native-bot react-native-bot added the Merged This PR has been merged. label Apr 28, 2026
@facebook-github-tools facebook-github-tools Bot added the Merged This PR has been merged. label Apr 28, 2026
@meta-codesync
Copy link
Copy Markdown

meta-codesync Bot commented Apr 28, 2026

This pull request has been merged in 0c153e2.

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. fb-exported Merged This PR has been merged. meta-exported p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants