Closed Bug 1325021 Opened 6 years ago Closed 6 years ago

Crash in java.lang.IllegalArgumentException: Doorhanger:Add was not registered at org.mozilla.gecko.EventDispatcher.unregisterListener(


(Firefox for Android Graveyard :: General, defect, P1)



(firefox52 unaffected, firefox-esr52 unaffected, firefox53 disabled, firefox54 disabled, firefox55 fixed, firefox58 verified)

Firefox 55
Tracking Status
firefox52 --- unaffected
firefox-esr52 --- unaffected
firefox53 --- disabled
firefox54 --- disabled
firefox55 --- fixed
firefox58 --- verified


(Reporter: sebastian, Assigned: droeh)



(Keywords: crash)

Crash Data


(3 files)

This bug was filed from the Socorro interface and is 
report bp-8c7e5664-d7b3-4ba2-8962-d5b362161221.
This is happened will switching between browser and custom tabs afaik.
This is weird. We register in the constructor of DoorHangerPopup and unregister when calling destroy(). There's no way to call destroy() without constructing the object first - so why are we not registered anymore?
DoorHangerPopup is initialized in onGlobalLayout(). Not sure is there any document or code guarantees that onGlobalLayout() will always be triggered before onDestroy() is called?

If onDestroy() is called without calling onGlobalLayout() before, this exception would be happened.
Here's a simple fix to make sure we do not call destroy() on the DoorHangerPopup multiple times, which will at least prevent this from being a crash.

The bigger issue here seems to be that we are hitting BrowserApp/GeckoApp.onDestroy() multiple times in a row without hitting GeckoApp.initialize() in between -- I haven't been able to reproduce this or figure out how it is occurring.
Assignee: nobody → droeh
Attachment #8845594 - Flags: review?(s.kaspari)
Attachment #8845594 - Flags: review?(s.kaspari) → review+
Pushed by
Set mDoorHangerPopup to null after destroying it. r=sebastian
Closed: 6 years ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 55
Still seems to happen in latest Nightly (e.g. bp-49acd1c2-3c4f-4269-8b49-b81d12170322)
Flags: needinfo?(droeh)
Resolution: FIXED → ---
(In reply to Jim Chen [:jchen] [:darchons] from comment #8)
> Still seems to happen in latest Nightly (e.g.
> bp-49acd1c2-3c4f-4269-8b49-b81d12170322)

Yeah. This particular bug is essentially the same as bug 1338055*; unfortunately, fixing it just leads to another crash when taking the same steps. I'll likely land a single patch to handle this and the other crashes in bug 1347584 when I have them figured out.

* - Except instead of swiping to kill a custom tab while Fennec is open, we trigger this by swiping to kill Fennec while a custom tab is open.
Flags: needinfo?(droeh)
Hi Julian 
I think you are working on CustomTab now. Do you have any idea ?
Flags: needinfo?(walkingice0204)
Hi Sebastian
Please help look at this code..[0]
Do you think the collection / remove logic could be the culprit?

Flags: needinfo?(s.kaspari)
In CustomTabs the code just extends GeckoApp and haven't touch anything relate to DoorHanger.
Flags: needinfo?(walkingice0204)
(In reply to Nevin Chen [:nechen] from comment #11)
> Hi Sebastian
> Please help look at this code..[0]
> Do you think the collection / remove logic could be the culprit?

Yeah, that is very likely. Most of those components are written with the constraint that there will always only be one BrowserApp/GeckoApp instance. However now with custom tabs and web apps this is no longer true.

We register for the event in the constructor of DoorHangerPopup (via GeckoApp). However we only call destroy() from BrowserApp and never from CustomTabsActivity. This looks wrong. Apart from that we should audit that both activities (or multiple in general) can register/unregister and do not interfere with each other.
Flags: needinfo?(s.kaspari)
Hi Dylan 
Per comment 13, I think the foundamental fix is to use the safer way to remove items in the collection.
Maybe you can add the fix to your patch? Please feel free to let me know how do you think.
Flags: needinfo?(droeh)
So the problem that's happening here is that we're trying to remove listeners from an EventDispatcher that belongs to a separate activity; I don't think a change in how we remove items from the collection would be able to fix this; at best it would be papering over the bug.

I'm trying to address all the crashes that happen when you swipe-to-kill Fennec while focused on a custom tab, and part of that will be making sure that the listener unregistering that happens in BrowserApp.onDestroy() will be done on the correct EventDispatcher; another part, which Sebastian brought up, is making sure there is creation/destruction parity -- nothing should be created in GeckoApp and destroyed in BrowserApp or vice versa, etc.
Flags: needinfo?(droeh)
Duplicate of this bug: 1352378
Also seen during development of bug 1351739 when enabling "Don't keep activities".
There, I'm launching a CustomTabsActivity from inside BrowserApp, so we end up with a sequence of
- BrowserApp onPause
- CustomTabs onCreate/Start/Resume
- BrowserApp onStop/Destroy and crash,

which I guess is the same sequence that happens when you keep activities, but then manually swipe the background activity away.
Blocks: 1351739
Comment on attachment 8853740 [details]
Bug 1325021 - Safely removing the listener in the collection to prevent concurrency issues.

In the situation described above in comment 17, this now crashes with

> 04-02 22:32:19.426 14616-14616 E/GeckoCrashHandler: >>> REPORTING UNCAUGHT EXCEPTION FROM THREAD 1 ("main")
> java.lang.UnsupportedOperationException
>    at java.util.concurrent.CopyOnWriteArrayList$CowIterator.remove(
>   at org.mozilla.gecko.EventDispatcher.safelyRemove(
>    at org.mozilla.gecko.EventDispatcher.unregisterListener(
>    at org.mozilla.gecko.EventDispatcher.unregisterGeckoThreadListener(
>    at org.mozilla.gecko.GeckoApp.onDestroy(
>    at org.mozilla.gecko.customtabs.CustomTabsActivity.onDestroy(
>    at
>    at
>    at
>    at
>    at
>    at$H.handleMessage(
>    at android.os.Handler.dispatchMessage(
>    at android.os.Looper.loop(
>    at
>    at java.lang.reflect.Method.invoke(Native Method)
>    at$
>    at
>    at

Actually in fact it's even worse than before, because now it crashes already when switching from custom tab to BrowserApp, whereas previously only the other route was affected. Besides, even without the above crash, your patch doesn't look like it solves the fundamental problem: The EventDispatcher wants to enforce (by crashing if necessary) that registering and unregistering of event listeners is done properly.
Attachment #8853740 - Flags: feedback-
Comment on attachment 8853740 [details]
Bug 1325021 - Safely removing the listener in the collection to prevent concurrency issues.

Looks like Jan has this covered.
Attachment #8853740 - Flags: review?(s.kaspari)
Blocks: 1285858
Priority: -- → P1
(In reply to Sebastian Kaspari (:sebastian) from comment #21)
> Comment on attachment 8853740 [details]
> Bug 1325021 - Safely removing the listener in the collection to prevent
> concurrency issues.
> Looks like Jan has this covered.

If this is no longer happening, we can close the bug.
Can you confirm?
Flags: needinfo?(s.kaspari)
I've been testing Focus as my primary browser lately - So I do not have much personal experience. Looking at the crash reports there's at least build 20170503100516 affected.
Flags: needinfo?(s.kaspari)
The saving grace is that these are diagnostic crashes (, so at least we won't crash on Beta/Release.
However as this means we're having some lifecycle issues with these event listeners, depending on how these occur exactly we might or might not experience some other doorhanger related issues on Beta/Release instead...
Right, I thought we could sidestep this with GeckoView-based custom tabs, but we actually run into a similar issue there as well. Here's a patch that should solve both.

I was aiming to remove GeckoApp.getEventDispatcher entirely, but unfortunately it's quite difficult to remove it from FormAssistPopup; we rely on being able to get the (instance) EventDispatcher in onAttachedToWindow there, and I don't see any obvious way of passing a GeckoApp reference to it before that happens. There are also some calls to GeckoApp.getEventDispatcher in testing, but I'm not so worried about those.
Attachment #8864581 - Flags: review?(nchen)
Comment on attachment 8864581 [details] [diff] [review]
Reduce reliance on GeckoAppShell.getGeckoInterface

Review of attachment 8864581 [details] [diff] [review]:

For FindInPageBar and FormAssistPopup, see if you can get the GeckoApp instance from the views themselves (see
Attachment #8864581 - Flags: review?(nchen) → review+
Pushed by
Reduce reliance on GeckoAppShell.getGeckoInterface to solve some custom tabs crashes. r=jchen
Closed: 6 years ago6 years ago
Resolution: --- → FIXED
The crash is not reproducing anymore, the changes made here were applied to a different implementation of PWAs, we can close the bug as fixed.
Product: Firefox for Android → Firefox for Android Graveyard
You need to log in before you can comment on or make changes to this bug.