Closed Bug 792702 Opened 7 years ago Closed 7 years ago

java.lang.IllegalThreadStateException: Expected thread 1 ("main"), but running on thread <n> ("GeckoBackgroundThread) at org.mozilla.gecko.GeckoApp.assertOnThread(GeckoApp.java)

Categories

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

16 Branch
ARM
Android
defect

Tracking

()

VERIFIED FIXED
Firefox 18
Tracking Status
firefox16 --- fixed
firefox17 --- verified
firefox18 --- verified
firefox19 --- verified
firefox20 --- verified

People

(Reporter: scoobidiver, Assigned: cpeterson)

References

(Blocks 1 open bug, )

Details

(Keywords: crash, regression, reproducible, Whiteboard: [native-crash])

Crash Data

Attachments

(1 file)

There's one crash in 18.0a1/20120919: bp-249094c2-7759-4ef3-817d-5f49c2120920.

java.lang.IllegalThreadStateException: Expected thread 1 ("main"), but running on thread 9 ("GeckoBackgroundThread)
	at org.mozilla.gecko.GeckoApp.assertOnThread(GeckoApp.java:2658)
	at org.mozilla.gecko.GeckoApp.assertOnUiThread(GeckoApp.java:2645)
	at org.mozilla.gecko.PromptService.show(PromptService.java:186)
	at org.mozilla.gecko.ActivityHandlerHelper$FilePickerPromptRunnable.run(ActivityHandlerHelper.java:240)
	at android.os.Handler.handleCallback(Handler.java:587)
	at android.os.Handler.dispatchMessage(Handler.java:92)
	at android.os.Looper.loop(Looper.java:130)
	at org.mozilla.gecko.util.GeckoBackgroundThread.run(GeckoBackgroundThread.java:31)

More reports at:
https://crash-stats.mozilla.com/report/list?signature=java.lang.IllegalThreadStateException%3A+Expected+thread+1+%28%22main%22%29%2C+but+running+on+thread+9+%28%22GeckoBackgroundThread%29+at+org.mozilla.gecko.GeckoApp.assertOnThread%28GeckoApp.java%29
kats, I think the FilePickerPromptRunnable should be posted to the UI thread' GeckoAppShell.getMainHandler(), not the GeckoBackgroundThread's GeckoAppShell.getHandler():

https://hg.mozilla.org/mozilla-central/annotate/6a2d1a3556b9/mobile/android/base/ActivityHandlerHelper.java#l151

I think we should rename these GeckoAppShell Handler getters to something clearer like getUiThreadHandler() and getBackgroundThreadHandler() (and remove getGeckoHandler() because it is not used).
Priority: -- → P2
Sounds reasonable to me. Do you want me to do it or will you?
I can fix the crash, since I added the assertOnUiThread() call when fixing a related PromptService bug. :)

Aurora 17 and Beta 16 don't call assertOnUiThread() here, but they still have the bug. This bug is likely contributing to the CalledFromWrongThreadException topcrashes.
Assignee: nobody → cpeterson
Status: NEW → ASSIGNED
Priority: P2 → P1
Post FilePicker dialog to UI thread, not GeckoBackgroundThread.
Attachment #663128 - Flags: review?(bugmail.mozilla)
Blocks: 792973
btw, my fix reveals a bunch of FilePicker StrictMode warnings. I confirmed that these warnings at not a regression from my patch, so I filed new bug 792973.
Attachment #663128 - Flags: review?(bugmail.mozilla) → review+
Blocks: 786312
Comment on attachment 663128 [details] [diff] [review]
post-FilePicker-to-UI-thread.patch

[Approval Request Comment]
Bug caused by (feature/regressing bug #): bug 786312
User impact if declined: Nightly 18 has 100% repro crashes when trying to use FilePicker (e.g. Bugzilla attachment). Aurora 17 and Beta 16 don't immediately crash here, but they still have the logic bug. This bug is likely contributing to 17 and 16's CalledFromWrongThreadException topcrashes.
Testing completed (on m-c, etc.): Tested locally with 100% STR
Risk to taking this patch (and alternatives if risky): Low risk. Android-only java one-liner. Some UI code was running on a background thread, but it should only run on the UI thread.
String or UUID changes made by this patch: N/A
Attachment #663128 - Flags: approval-mozilla-beta?
Attachment #663128 - Flags: approval-mozilla-aurora?
Keywords: regression
Version: Trunk → Firefox 16
Crash Signature: [@ java.lang.IllegalThreadStateException: Expected thread 1 ("main"), but running on thread 9 ("GeckoBackgroundThread) at org.mozilla.gecko.GeckoApp.assertOnThread(GeckoApp.java)] → [@ java.lang.IllegalThreadStateException: Expected thread 1 ("main"), but running on thread 9 ("GeckoBackgroundThread) at org.mozilla.gecko.GeckoApp.assertOnThread(GeckoApp.java)] [@ java.lang.IllegalThreadStateException: Expected thread 1 ("main") but r…
Summary: java.lang.IllegalThreadStateException: Expected thread 1 ("main"), but running on thread 9 ("GeckoBackgroundThread) at org.mozilla.gecko.GeckoApp.assertOnThread(GeckoApp.java) → java.lang.IllegalThreadStateException: Expected thread 1 ("main"), but running on thread <n> ("GeckoBackgroundThread) at org.mozilla.gecko.GeckoApp.assertOnThread(GeckoApp.java)
Crash Signature: [@ java.lang.IllegalThreadStateException: Expected thread 1 ("main"), but running on thread 9 ("GeckoBackgroundThread) at org.mozilla.gecko.GeckoApp.assertOnThread(GeckoApp.java)] [@ java.lang.IllegalThreadStateException: Expected thread 1 ("main") but r… → [@ java.lang.IllegalThreadStateException: Expected thread 1 ("main"), but running on thread 9 ("GeckoBackgroundThread) at org.mozilla.gecko.GeckoApp.assertOnThread(GeckoApp.java) ] [@ java.lang.IllegalThreadStateException: Expected thread 1 ("main") but …
Triage drive-by:  Likely we can take this on Monday if it has been landed on trunk before then without any known fallout.
(In reply to Lukas Blakk [:lsblakk] from comment #9)
> Triage drive-by:  Likely we can take this on Monday if it has been landed on
> trunk before then without any known fallout.

I am testing a band-aid fix now.
^ oops! My comment about a "band-aid fix" was intended for bug 747629, not this bug! <:)
https://hg.mozilla.org/mozilla-central/rev/dbed92805ae7
Status: ASSIGNED → RESOLVED
Closed: 7 years ago
Flags: in-testsuite-
Resolution: --- → FIXED
Comment on attachment 663128 [details] [diff] [review]
post-FilePicker-to-UI-thread.patch

(In reply to Lukas Blakk [:lsblakk] from comment #9)
> Triage drive-by:  Likely we can take this on Monday if it has been landed on
> trunk before then without any known fallout.

lsblakk, renomming for aurora? and beta?

I landed my patch on 09-21, so the first build to include my fix was 09-22. Before my fix, I see about a dozen crash reports in builds 09-20 and 09-21. After my fix, I see no crash reports in builds 09-22, 09-23, or 09-24.
Attachment #663128 - Flags: approval-mozilla-beta?
Attachment #663128 - Flags: approval-mozilla-beta+
Attachment #663128 - Flags: approval-mozilla-aurora?
Attachment #663128 - Flags: approval-mozilla-aurora+
This crash doesn't occur on any branch if I perform the STR from comment #4. Closing bug as verified fixed on:

Firefox 20.0a1 (2012-11-21)
Device: Galaxy S2
OS: Android 4.0.3
You need to log in before you can comment on or make changes to this bug.