Last Comment Bug 792702 - java.lang.IllegalThreadStateException: Expected thread 1 ("main"), but running on thread <n> ("GeckoBackgroundThread) at org.mozilla.gecko.GeckoApp.assertOnThread(GeckoApp.java)
: java.lang.IllegalThreadStateException: Expected thread 1 ("main"), but runnin...
Status: VERIFIED FIXED
[native-crash]
: crash, regression, reproducible
Product: Firefox for Android
Classification: Client Software
Component: General (show other bugs)
: 16 Branch
: ARM Android
: P1 critical (vote)
: Firefox 18
Assigned To: Chris Peterson [:cpeterson]
:
Mentors:
http://www.w3schools.com/tags/tryit.a...
Depends on:
Blocks: 792973 786312
  Show dependency treegraph
 
Reported: 2012-09-20 02:19 PDT by Scoobidiver (away)
Modified: 2012-11-21 07:04 PST (History)
5 users (show)
ryanvm: in‑testsuite-
See Also:
Crash Signature:
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---
fixed
verified
verified
verified
verified


Attachments
post-FilePicker-to-UI-thread.patch (1.07 KB, patch)
2012-09-20 13:08 PDT, Chris Peterson [:cpeterson]
bugmail.mozilla: review+
lukasblakk+bugs: approval‑mozilla‑aurora+
lukasblakk+bugs: approval‑mozilla‑beta+
Details | Diff | Review

Description Scoobidiver (away) 2012-09-20 02:19:36 PDT
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
Comment 1 Chris Peterson [:cpeterson] 2012-09-20 10:40:34 PDT
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).
Comment 2 (Back on May31) Kartikaya Gupta (email:kats@mozilla.com) 2012-09-20 11:23:39 PDT
Sounds reasonable to me. Do you want me to do it or will you?
Comment 3 Chris Peterson [:cpeterson] 2012-09-20 11:54:09 PDT
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.
Comment 4 Chris Peterson [:cpeterson] 2012-09-20 13:07:30 PDT
STR:
1. Load http://www.w3schools.com/tags/tryit.asp?filename=tryhtml_input_type_file
2. Press "Browse..." button
3. Choose a file
4. CRASH!
Comment 5 Chris Peterson [:cpeterson] 2012-09-20 13:08:23 PDT
Created attachment 663128 [details] [diff] [review]
post-FilePicker-to-UI-thread.patch

Post FilePicker dialog to UI thread, not GeckoBackgroundThread.
Comment 6 Chris Peterson [:cpeterson] 2012-09-20 13:31:09 PDT
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.
Comment 7 Chris Peterson [:cpeterson] 2012-09-20 16:54:46 PDT
https://hg.mozilla.org/integration/mozilla-inbound/rev/dbed92805ae7
Comment 8 Chris Peterson [:cpeterson] 2012-09-20 17:01:02 PDT
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
Comment 9 Lukas Blakk [:lsblakk] use ?needinfo 2012-09-21 16:11:35 PDT
Triage drive-by:  Likely we can take this on Monday if it has been landed on trunk before then without any known fallout.
Comment 10 Chris Peterson [:cpeterson] 2012-09-21 16:23:27 PDT
(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.
Comment 11 Chris Peterson [:cpeterson] 2012-09-21 18:51:55 PDT
^ oops! My comment about a "band-aid fix" was intended for bug 747629, not this bug! <:)
Comment 12 Ryan VanderMeulen [:RyanVM] 2012-09-21 19:58:57 PDT
https://hg.mozilla.org/mozilla-central/rev/dbed92805ae7
Comment 13 Chris Peterson [:cpeterson] 2012-09-24 12:04:56 PDT
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.
Comment 15 Cristian Nicolae (:xti) 2012-11-21 07:04:00 PST
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

Note You need to log in before you can comment on or make changes to this bug.