Closed Bug 1697248 Opened 4 years ago Closed 2 years ago

Crash in [@ org.mozilla.geckoview.GeckoResult$UncaughtException: at org.mozilla.geckoview.GeckoResult.dispatchLocked] "Must have a Handler"

Categories

(GeckoView :: Extensions, defect, P3)

Unspecified
Android
defect

Tracking

(Not tracked)

RESOLVED WORKSFORME

People

(Reporter: agi, Unassigned)

References

Details

(Keywords: crash, Whiteboard: [geckoview:m88])

Crash Data

Crash report: https://crash-stats.mozilla.org/report/index/2cd0b068-2f67-48b2-b2db-4b08c0210309

Java stack trace:

org.mozilla.geckoview.GeckoResult$UncaughtException
	at org.mozilla.geckoview.GeckoResult.dispatchLocked(GeckoResult.java:4)
	at org.mozilla.geckoview.GeckoResult.completeExceptionally(GeckoResult.java:4)
	at org.mozilla.geckoview.GeckoResult.lambda$thenInternal$4$GeckoResult(GeckoResult.java:10)
	at org.mozilla.geckoview.-$$Lambda$GeckoResult$-hYJKiV7OmgfRN8NZFvKg9ij7nk.run(Unknown Source:8)
	at android.os.Handler.handleCallback(Handler.java:938)
	at android.os.Handler.dispatchMessage(Handler.java:99)
	at android.os.Looper.loop(Looper.java:246)
	at android.app.ActivityThread.main(ActivityThread.java:8506)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)

Lots of these seem to be in extension code, e.g.: https://crash-stats.mozilla.org/report/index/da0213cd-e44a-4f6a-87b4-5fff30210308

org.mozilla.geckoview.GeckoResult$UncaughtException: java.lang.IllegalThreadStateException: Must have a Handler
	at org.mozilla.geckoview.GeckoResult.dispatchLocked(GeckoResult.java:4)
	at org.mozilla.geckoview.GeckoResult.completeExceptionally(GeckoResult.java:4)
	at org.mozilla.geckoview.GeckoResult.lambda$thenInternal$4$GeckoResult(GeckoResult.java:10)
	at org.mozilla.geckoview.-$$Lambda$GeckoResult$-hYJKiV7OmgfRN8NZFvKg9ij7nk.run(lambda)
	at android.os.Handler.handleCallback(Handler.java:739)
	at android.os.Handler.dispatchMessage(Handler.java:95)
	at android.os.Looper.loop(Looper.java:158)
	at android.app.ActivityThread.main(ActivityThread.java:7224)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: java.lang.IllegalThreadStateException: Must have a Handler
	at org.mozilla.geckoview.GeckoResult.then(GeckoResult.java:4)
	at org.mozilla.geckoview.GeckoResult.map(GeckoResult.java:4)
	at org.mozilla.geckoview.GeckoResult.map(GeckoResult.java:1)
	at org.mozilla.geckoview.WebExtensionController.closeTab(WebExtensionController.java:5)
	at org.mozilla.geckoview.WebExtensionController.lambda$handleMessage$1$WebExtensionController(WebExtensionController.java:6)
	at org.mozilla.geckoview.-$$Lambda$WebExtensionController$cy4tUfKhvCERfC7glVoFTwHAvqU.accept(lambda)
	at org.mozilla.geckoview.GeckoResult.lambda$accept$2(GeckoResult.java:1)
	at org.mozilla.geckoview.-$$Lambda$GeckoResult$jOTMkpkhFSpBCw69vbWxDq7m7Tw.onValue(lambda)
	at org.mozilla.geckoview.GeckoResult.lambda$thenInternal$4$GeckoResult(GeckoResult.java:2)
	... 8 more

or https://crash-stats.mozilla.org/report/index/9e63fcfe-4fba-414f-bae8-dcf680210309

org.mozilla.geckoview.GeckoResult$UncaughtException: java.lang.IllegalThreadStateException: Must have a Handler
	at org.mozilla.geckoview.GeckoResult.dispatchLocked(GeckoResult.java:4)
	at org.mozilla.geckoview.GeckoResult.completeExceptionally(GeckoResult.java:4)
	at org.mozilla.geckoview.GeckoResult.lambda$thenInternal$4$GeckoResult(GeckoResult.java:10)
	at org.mozilla.geckoview.-$$Lambda$GeckoResult$-hYJKiV7OmgfRN8NZFvKg9ij7nk.run(Unknown Source:8)
	at android.os.Handler.handleCallback(Handler.java:938)
	at android.os.Handler.dispatchMessage(Handler.java:99)
	at android.os.Looper.loop(Looper.java:223)
	at android.app.ActivityThread.main(ActivityThread.java:7660)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
Caused by: java.lang.IllegalThreadStateException: Must have a Handler
	at org.mozilla.geckoview.GeckoResult.then(GeckoResult.java:4)
	at org.mozilla.geckoview.GeckoResult.map(GeckoResult.java:4)
	at org.mozilla.geckoview.GeckoResult.map(GeckoResult.java:1)
	at org.mozilla.geckoview.WebExtensionController.updateTab(WebExtensionController.java:9)
	at org.mozilla.geckoview.WebExtensionController.lambda$handleMessage$1$WebExtensionController(WebExtensionController.java:4)
	at org.mozilla.geckoview.-$$Lambda$WebExtensionController$cy4tUfKhvCERfC7glVoFTwHAvqU.accept(Unknown Source:17)
	at org.mozilla.geckoview.GeckoResult.lambda$accept$2(GeckoResult.java:1)
	at org.mozilla.geckoview.-$$Lambda$GeckoResult$jOTMkpkhFSpBCw69vbWxDq7m7Tw.onValue(Unknown Source:2)
	at org.mozilla.geckoview.GeckoResult.lambda$thenInternal$4$GeckoResult(GeckoResult.java:2)
	... 8 more

At first glance, this doesn't make any sense. We should always run these handlers in the UI thread, so how do we not have a Handler there?

Assignee: nobody → agi
Severity: -- → S3
Priority: -- → P1
Whiteboard: [geckoview:m88]

Turns out this signature has many causes, one of these was the one in Comment 2 which was fixed by Bug 1697270 (and AC's patch: https://github.com/mozilla-mobile/android-components/commit/3d378508505d9c1d51a4fb6bb61243a90243eb47 )

Opened Bug 1698823 for another one that's GeckoView-related.

Depends on: 1698823

Also willkg is looking into improving the signature in socorro (long term)

Flags: needinfo?(willkg)

Signature generation for Java crashes is pretty mediocre in Socorro currently. I've been working on improving that.

Tracker bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1541120

I could use more help finding signatures that are unhelpful and figuring out better signatures so we can hone in on a better algorithm.

Flags: needinfo?(willkg)

From what I can see the remaining crashes in this signature are generic OOMs. Not sure what we can do about those.

Caused by: java.lang.OutOfMemoryError: OutOfMemoryError thrown while trying to throw OutOfMemoryError; no stack trace available
Assignee: agi → nobody
Severity: S3 → --
Priority: P1 → --
Severity: -- → S3
Priority: -- → P3

I saw this Must have a Handler exception when installing an extension from a Kotlin coroutine running on other the Main Dispatcher.
And fixed it by switching to using Main (here).
The Main thread has a Looper / Handler. Other threads used by coroutines do not.
I imagine there's some Handler Message communication in GV related to GeckoResults ?
If all these reports stem from code called in a coroutine we probably don't want that to be on a background thread that can be shutdown at any time.

Flags: needinfo?(agi)
Flags: needinfo?(agi)
Depends on: 1743169
OS: Unspecified → Android
Crash Signature: [@ org.mozilla.geckoview.GeckoResult$UncaughtException: at org.mozilla.geckoview.GeckoResult.dispatchLocked(GeckoResult.java)] → [@ org.mozilla.geckoview.GeckoResult$UncaughtException: at org.mozilla.geckoview.GeckoResult.dispatchLocked]
Summary: Crash in [@ org.mozilla.geckoview.GeckoResult$UncaughtException: at org.mozilla.geckoview.GeckoResult.dispatchLocked(GeckoResult.java)] → Crash in [@ org.mozilla.geckoview.GeckoResult$UncaughtException: at org.mozilla.geckoview.GeckoResult.dispatchLocked]

I don't see any recent crash reports with "Must have a Handler" in the "java stack trace raw" field

Status: NEW → RESOLVED
Crash Signature: [@ org.mozilla.geckoview.GeckoResult$UncaughtException: at org.mozilla.geckoview.GeckoResult.dispatchLocked] → [@ org.mozilla.geckoview.GeckoResult$UncaughtException: at org.mozilla.geckoview.GeckoResult.dispatchLocked(GeckoResult.java)]
Closed: 2 years ago
Resolution: --- → WORKSFORME
Summary: Crash in [@ org.mozilla.geckoview.GeckoResult$UncaughtException: at org.mozilla.geckoview.GeckoResult.dispatchLocked] → Crash in [@ org.mozilla.geckoview.GeckoResult$UncaughtException: at org.mozilla.geckoview.GeckoResult.dispatchLocked] "Must have a Handler"

Some related discussion to this root issue may have happened in bug 1877588. Linking it to this one in case the crash ever comes back. The discussion on this bug helped me understand what was happening in my case too.

See Also: → 1877588
You need to log in before you can comment on or make changes to this bug.