Skip to content

Gate printMountItem in error handlers behind enableFabricLogs#56012

Closed
JakobFelixJulius wants to merge 2 commits intofacebook:mainfrom
JakobFelixJulius:fix-mountitemdispatcher-oom-printmountitem
Closed

Gate printMountItem in error handlers behind enableFabricLogs#56012
JakobFelixJulius wants to merge 2 commits intofacebook:mainfrom
JakobFelixJulius:fix-mountitemdispatcher-oom-printmountitem

Conversation

@JakobFelixJulius
Copy link
Copy Markdown
Contributor

@JakobFelixJulius JakobFelixJulius commented Mar 9, 2026

Summary:

Two printMountItem() call sites in MountItemDispatcher.kt error handlers are not gated behind ReactNativeFeatureFlags.enableFabricLogs(), while every other printMountItem call site in the same file is.

When a Fabric mount operation fails under memory pressure, the unguarded error handler calls toString() on every mount item in the batch — each using String.format() — which triggers a fatal OutOfMemoryError (Android 256MB heap limit). The device is already low on memory when the original mount error occurs, so allocating diagnostic strings for the entire batch is the killing blow.

Impact: 67 affected users in production, 87% Android 16, all Samsung devices.

Production stacktrace (67 occurrences)
java.lang.OutOfMemoryError: Failed to allocate a 48 byte allocation with 2222800 free bytes and 2170KB until OOM, target footprint 268435456, growth limit 268435456; giving up on allocation because <1% of heap free after GC.
at java.util.Formatter.parse(Formatter.java:2737)
at java.util.Formatter.format(Formatter.java:2686)
at java.util.Formatter.format(Formatter.java:2640)
at java.lang.String.format(String.java:4489)
at com.facebook.react.fabric.mounting.mountitems.IntBufferBatchMountItem.toString(IntBufferBatchMountItem.kt:220)
at com.facebook.react.fabric.mounting.MountItemDispatcher$Companion.printMountItem(MountItemDispatcher.kt:358)
at com.facebook.react.fabric.mounting.MountItemDispatcher$Companion.access$printMountItem(MountItemDispatcher.kt:337)
at com.facebook.react.fabric.mounting.MountItemDispatcher.dispatchMountItems(MountItemDispatcher.kt:230)
at com.facebook.react.fabric.mounting.MountItemDispatcher.tryDispatchMountItems(MountItemDispatcher.kt:88)
at com.facebook.react.fabric.FabricUIManager$DispatchUIFrameCallback.doFrameGuarded(FabricUIManager.java:1484)
at com.facebook.react.uimanager.GuardedFrameCallback.doFrame(GuardedFrameCallback.kt:25)
at com.facebook.react.modules.core.ReactChoreographer.frameCallback$lambda$1(ReactChoreographer.kt:59)

Device: Samsung SM-S938B (Galaxy S25 Ultra), Android 16, 12GB RAM
Heap limit: 256MB, <1% free after GC

Fix:
Gate the two remaining printMountItem call sites behind enableFabricLogs(), matching the existing pattern used at all other call sites in the same file.

Changelog:

[ANDROID] [FIXED] - Gate diagnostic printMountItem calls in MountItemDispatcher error handlers behind enableFabricLogs() to prevent OOM crash

Test Plan:

Applied as a patch to a production app. OOM crash from the unguarded error handler path no longer occurs — confirmed over several weeks with 67 previously affected users.

The change is strictly additive gating — no logic changes. All other printMountItem call sites in the same file already use the same enableFabricLogs() guard, so this just makes the two error-handler sites consistent.

Summary:
Two `printMountItem()` call sites in `MountItemDispatcher.kt` error
handlers are not gated behind `enableFabricLogs()`, while all other
call sites in the same file are. When a Fabric mount operation fails
under memory pressure, the unguarded error handler calls `toString()`
on every mount item in the batch via `String.format()`, triggering a
fatal OutOfMemoryError on Android (256MB heap limit).

This affects 67 users in production — 87% Android 16, all Samsung
devices.

## Changelog:
[Android] [Fixed] - Gate diagnostic printMountItem calls in MountItemDispatcher error handlers behind enableFabricLogs to prevent OOM crash
@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 Mar 9, 2026
Re-add the "We want to mark the mount item that caused exception"
comment that was inadvertently removed in the previous commit.

Made-with: Cursor
@facebook-github-bot facebook-github-bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Mar 9, 2026
@Satttoshi
Copy link
Copy Markdown

This would be huge, I have the same OOM crashes with my Android users and it all points down to this.

@meta-codesync
Copy link
Copy Markdown

meta-codesync Bot commented Mar 20, 2026

@alanleedev has imported this pull request. If you are a Meta employee, you can view this in D97414011.

@meta-codesync meta-codesync Bot closed this in 7a546f9 Mar 20, 2026
@react-native-bot
Copy link
Copy Markdown
Collaborator

This pull request was successfully merged by @JakobFelixJulius in 7a546f9

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

meta-codesync Bot commented Mar 20, 2026

@alanleedev merged this pull request in 7a546f9.

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. Merged This PR has been merged. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants