Closed Bug 889881 Opened 11 years ago Closed 11 years ago

ANR: GeckoAppShell.pumpMessageLoop() can block the Gecko thread

Categories

(Firefox for Android Graveyard :: General, defect)

All
Android
defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED
Firefox 25

People

(Reporter: jchen, Assigned: jchen)

Details

(Whiteboard: [ANR])

Attachments

(2 files)

GeckoAppShell.pumpMessageLoop() calls GeckoAppShell.getNextMessageFromQueue() through JNI to retrieve the next message from the Gecko thread message queue. Because we don't want MessageQueue.next() to block, getNextMessageFromQueue() bails if |MessageQueue.mMessages == null|. However that's not a reliable way to detect whether MessageQueue.next() will block or not, and it can still block if there are pending messages (e.g. delayed messages). Once MessageQueue.next() blocks, the Gecko thread is blocked, causing unresponsiveness and ANRs.
We first need a Gecko handler in order for the fix to work. This patch also moves setting the Gecko thread/handler to inside GeckoThread.
Attachment #770842 - Flags: review?(blassey.bugs)
The fix here uses an IdleHandler to detect when MessageQueue.next() is going to block or not, instead of checking MessageQueue.mMessages. The IdleHandler cannot throw an Exception to prevent blocking, but it can queue a new, special message. This new message gets returned in MessageQueue.next() and we return early when we detect this message (this patch uses Message.obj to set/detect the special message).
Attachment #770844 - Flags: review?(blassey.bugs)
Attachment #770842 - Flags: review?(blassey.bugs) → review+
Comment on attachment 770844 [details] [diff] [review]
Use IdleHandler to make MessageQueue.next() not block (v1)

Review of attachment 770844 [details] [diff] [review]:
-----------------------------------------------------------------

Not going to lie, there is some black magic in this code. Let's keep an eye out for flash bugs after this lands.
Attachment #770844 - Flags: review?(blassey.bugs) → review+
https://hg.mozilla.org/mozilla-central/rev/66427620c3cd
https://hg.mozilla.org/mozilla-central/rev/487b02e3c084
Status: ASSIGNED → RESOLVED
Closed: 11 years ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 25
Product: Firefox for Android → Firefox for Android Graveyard
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: