Crash in [@ java.lang.OutOfMemoryError: at android.os.Message.obtain(Message.java)]
Categories
(GeckoView :: General, defect, P2)
Tracking
(firefox160 wontfix, firefox161 affected, firefox162 affected, firefox163 affected)
People
(Reporter: aryx, Assigned: m_kato)
References
(Blocks 1 open bug, Regression)
Details
(Keywords: crash, regression)
Crash Data
There were few crashes with this signature until the end of August when crash volume increases for the first time (might be only Nightly or a staged rollout). Since early October, crash volume has been steadily increasing to ~130 reports/day. Most of the reports are for Android 17.
Crash report: https://crash-stats.mozilla.org/report/index/c6da3a42-6bf5-418b-b676-8f83a0261105
Top 10 frames:
0 android.os.Message obtain Message.java:238
1 android.os.Handler getPostMessage Handler.java:1081
2 android.os.Handler post Handler.java:488
3 kotlinx.coroutines.android.HandlerContext dispatch HandlerDispatcher.kt:3
4 kotlinx.coroutines.internal.DispatchedContinuationKt safeDispatch DispatchedContinuation.kt:1
5 kotlinx.coroutines.CancellableContinuationImpl dispatchResume CancellableContinuationImpl.kt:66
6 kotlinx.coroutines.CancellableContinuationImpl resumeImpl$kotlinx_coroutines_core CancellableContinuationImpl.kt:41
7 kotlinx.coroutines.CancellableContinuationImpl resumeWith CancellableContinuationImpl.kt:17
8 kotlinx.coroutines.flow.SharedFlowImpl tryEmit SharedFlow.kt:32
9 kotlinx.coroutines.flow.SharedFlowImpl emit SharedFlow.kt:1
Updated•18 days ago
|
Updated•18 days ago
|
Comment 1•18 days ago
|
||
@owlish could this be triaged for severity and priority?
@mcarare looks like this is fallout from 2052790
From Claude:
The likely regressor is bug 2052790, "Update targetSdkVersion to 37" (landed July 6 in 154.0a1). Targeting API 37 opts Fenix into Android 17's new lock-free MessageQueue, and GeckoView depends on the old queue's internals. Confidence is medium to high on the trigger. The exact way it fills the heap is a hypothesis I haven't reproduced.
The evidence
It's specific to Android 17, and only from 154 on. 74% of all crashes, and 77–89% for each version from 154 onward, are on Android 17, mostly Pixels. Versions 153 and older have zero Android 17 crashes.
153 and 154 side by side. From August 14 to 31, while both were on release, Android 17 users on 153 had 0 of these out of 1,617 crashes. On 154 they had 169 of 6,816 (2.5%).
Other Android versions are flat at about 60–100 crashes a week throughout. The climb since late August (about 30, then 123, up to 747 a week) is all Android 17, and grows as more users move to it.
Same pattern as bug 2086228 (the QrFragment camera crash): nothing on Android 17 before 154, then rising with Android 17 adoption. Both trace back to the targetSdk 37 change.Why targeting 37 matters here
Android 17 changes MessageQueue for apps targeting API 37 (https://developer.android.com/about/versions/17/behavior-changes-17). The new queue is lock-free and works differently inside; Google's guidance (https://developer.android.com/about/versions/17/changes/messagequeue) says code that reflects on its private fields or methods will break, and that mMessages is now always null.
GeckoView relies on exactly those internals to run its own event loop on the Gecko thread:
The pump: AndroidBridge::PumpMessageLoop() (widget/android/AndroidBridge.cpp) calls the hidden MessageQueue.next() through JNI. To avoid blocking, it first checks MessageQueue.isIdle() and skips the pump if the queue is idle.
The idle handler: in GeckoThread.run(), an IdleHandler creates a "queue is empty" Message with Message.obtain and pushes it to the front of the queue every time the queue goes idle. It never removes itself (return true).
Recent history: in March, bug 2021365 already replaced reading mMessages with isIdle(), but the private next() call remained.
Comment 2•17 days ago
|
||
I think :m_kato would be better suited for fixing these issues.
| Assignee | ||
Comment 3•14 days ago
|
||
I am not sure that Claude analysis is correct. OOM by Message.obtain occurs on pre Android 17 such as Android 16 too. Although Android 17 moves to concurrent message queue, I guess that it hits OOM since message loop is called frequency. Although We might have to call message.recyleUnchecked like Looper.loop, message isn't reused after pumping message, so it will be disposed by GC.
| Assignee | ||
Comment 4•14 days ago
|
||
When I check AOSP code for Message.obtain(), legacy message queue doesn't allocate new Message object. It is from object poll. But new concurrent message queue always allocates new Message object. So since it is different, Message.obtain hits OOM on Android 17. Before Android 16, I think this OOM occurs on other code.
| Assignee | ||
Comment 5•13 days ago
|
||
Most OOM seems to cause on IPC I/O Parent thread. I guess that this might be from GPU process and it might causes by heavy IPC from GPU process. Example, touch event etc is posted from GPU process to Android UI thread. I think we can optimize requestUiThreadCallback at first (Bug 2091233) to reduce Message object allocation.
| Assignee | ||
Updated•11 days ago
|
Comment 6•11 days ago
|
||
Bug 2091233 has landed.
:m_kato, what are the next steps here? The volume was low in nightly.
I'm not sure if 2091233 is suitable for a beta uplift request
Updated•10 days ago
|
Updated•7 days ago
|
| Assignee | ||
Updated•6 days ago
|
| Assignee | ||
Comment 7•6 days ago
|
||
Bug 2091233 has been uplifted to beta. I would like to watch crash data after that.
Message.obtain allocates a few memory under 32bytes. So when this OOM occur, process is under low memory situation.
Comment 8•4 days ago
|
||
Set release status flags based on info from the regressing bug 2052790
Comment 9•5 hours ago
|
||
FYI we are still crashing with 161.0
Description
•