New issue
Advanced search Search tips

Issue 630709 link

Starred by 2 users

Issue metadata

Status: Fixed
Owner:
Closed: Aug 2016
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: Android
Pri: 2
Type: ----



Sign in to add a comment

WebViewThreadTest#testWebViewInitByWebStorage failing due to wrong thread

Project Member Reported by tedc...@chromium.org, Jul 22 2016

Issue description

be6b0:  07-22 19:07:39.336  4392  4424 E AndroidRuntime: java.lang.IllegalStateException: Must be called on the Ui thread.
be6b0:  07-22 19:07:39.336  4392  4424 E AndroidRuntime: 	at org.chromium.base.ThreadUtils.assertOnUiThread(ThreadUtils.java:193)
be6b0:  07-22 19:07:39.336  4392  4424 E AndroidRuntime: 	at org.chromium.android_webview.AwQuotaManagerBridge.getInstance(AwQuotaManagerBridge.java:28)
be6b0:  07-22 19:07:39.336  4392  4424 E AndroidRuntime: 	at com.android.webview.chromium.WebViewChromiumFactoryProvider.getWebStorage(WebViewChromiumFactoryProvider.java:467)
be6b0:  07-22 19:07:39.336  4392  4424 E AndroidRuntime: 	at android.webkit.WebStorage.getInstance(WebStorage.java:194)
be6b0:  07-22 19:07:39.336  4392  4424 E AndroidRuntime: 	at org.chromium.webview_shell.test.WebViewThreadTest$4.run(WebViewThreadTest.java:91)
be6b0:  07-22 19:07:39.336  4392  4424 E AndroidRuntime: 	at org.chromium.webview_shell.test.WebViewThreadTest$5.run(WebViewThreadTest.java:102)
be6b0:  07-22 19:07:39.336  4392  4424 E AndroidRuntime: 	at java.lang.Thread.run(Thread.java:818)

https://build.chromium.org/p/chromium.android/builders/Android%20Webview%20L%20(dbg)

I recently made a change that changed from an assert to a proper
exception for this check, so it exposed this bug.

 
Cc: boliu@chromium.org

Comment 2 by boliu@chromium.org, Jul 22 2016

then I think said exception needs to be reverted, or fixed...

Comment 3 by boliu@chromium.org, Jul 22 2016

Components: Mobile>WebView

Comment 4 by boliu@chromium.org, Jul 22 2016

or webview has a bug somewhere about marking which thread is UI, hmm...

Comment 5 by boliu@chromium.org, Jul 22 2016

Cc: torne@chromium.org
just disable the test short term

I guess the question is, can WebStorage be used on a non-UI thread before any webview is created.. I think if someone does that, we should just pick the main thread and the UI thread, and post everything to main thread. Torne, thoughts?
This definitely feels like a bug in WebView or the test, not something in my change as it would have failed if asserts worked on any WebView compatible OS

Comment 7 by boliu@chromium.org, Jul 22 2016

Current implementation marks whatever thread WebStorage is created on as the UI thread. But WebStorageAdapter lacks any thread hopping code (unlike say WebViewChromium). That's easy to fix. Anyone feeling up to it?

Comment 8 by boliu@chromium.org, Jul 22 2016

WebViewChromiumFactoryProvider doesn't have any thread checks/hops when interacting with chromium classes either.

> This definitely feels like a bug in WebView or the test, not something in my change as it would have failed if asserts worked on any WebView compatible OS

Yeah we can fix this.

Comment 9 by aluo@chromium.org, Jul 22 2016

Just to be sure, this doesn't require a fix in test code right?  The test is covering case where static method is called on non-UI thread, but then creates the webview on the UI thread at a later time.  This is to cover a case in 568602, which I assume is valid usage (didn't find in docs to the contrary). 

Comment 10 by boliu@chromium.org, Jul 22 2016

> Just to be sure, this doesn't require a fix in test code right? 

Right

Comment 11 by torne@chromium.org, Jul 25 2016

Cc: aluo@chromium.org
Owner: ----
Status: Available (was: Assigned)
Bo, I think you described it backward in comment 7. The onMainThread parameter has a confusing name - it means "initialise using the main thread as the UI thread, instead of the current thread", not "we are currently on the main thread" - if you are actually on the main thread then it doesn't matter whether it's true or false as the result is the same.

When you initialise WebView by calling any of the static methods (other than CookieManager which is special), it binds the UI thread to the main thread, *not* the current thread. The code then crashes because it immediately proceeds using the *current*, non-UI-thread, to call chromium functions that require that they're called on the UI thread.

So yeah, anywhere where the glue code calls something in chromium that requires that it be on the UI thread it needs to be wrapped in thread-hopping junk, and this isn't currently true in all cases. The test is indeed correct.

Comment 12 by torne@chromium.org, Jul 25 2016

Related question about the test, though: does the way we run tests guarantee that each of these tests will run in a *new process*? You only get one shot at webview initialisation per-process, so if the test isn't forcing a new process to be created each time then it may be more than just this one test that's broken, and it's just that only the one that runs first gets to crash?

Comment 14 by boliu@chromium.org, Jul 25 2016

Owner: boliu@chromium.org
Status: Assigned (was: Available)
I'll take this I guess

> Bo, I think you described it backward in comment 7.

Oops you are right. It's this stupid line that's impossible to read...

Looper looper = !onMainThread ? Looper.myLooper() : Looper.getMainLooper();

Comment 15 by torne@chromium.org, Jul 25 2016

If you're going to be changing stuff near here anyway, I vote change "onMainThread" to "useMainThread" and flip the ternary around so the condition isn't negated. :)

Comment 16 by aluo@chromium.org, Jul 25 2016

Re comment 12, the tests are run using the test_runner.py script, which does start a new process for each test method.

Comment 17 by boliu@chromium.org, Jul 25 2016

> Related question about the test, though: does the way we run tests guarantee that each of these tests will run in a *new process*?

These are just plain old instrumentation tests it looks like. So yes, each test runs in a new process. But that's more or less by accident rather than intention.

Comment 18 by boliu@chromium.org, Jul 25 2016

This is not that trivial. I think I'm going to move all the RunQueue logic from WebViewChromium into WebViewChromiumFactoryProvider instead, so it can be shared.

So there is going to one global queue rather than one per webview, which I think is probably fine..
Project Member

Comment 19 by bugdroid1@chromium.org, Jul 26 2016

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/fbfe162dd52f7901535ceb70edf719ef4a692046

commit fbfe162dd52f7901535ceb70edf719ef4a692046
Author: boliu <boliu@chromium.org>
Date: Tue Jul 26 17:56:39 2016

aw: Move thread hop code to ProviderFactory

So that the thread hopping code can be used from entry points other
than WebViewChromium.

Large CL, but mostly no-op. Moved these to ProivderFactory:
WebViewChromiumRunQueue
runBlockingFuture
runVoidTaskOnUiThreadBlocking
runOnUiThreadBlocking
addTask

Now FactoryProvider no longer needs to keep a list of WebViewChromiums
yet to be started. So remove all that logic along with startYourEngine,
and no longer need to drainQueue.

Subtle change in behavior is tasks for a single WebViewChromium used to
be grouped together and now are all appended to a single queue that's
drained at start up. This should not cause problems.

BUG= 630709 

Review-Url: https://codereview.chromium.org/2182683003
Cr-Commit-Position: refs/heads/master@{#407848}

[modify] https://crrev.com/fbfe162dd52f7901535ceb70edf719ef4a692046/android_webview/glue/java/src/com/android/webview/chromium/WebViewChromium.java
[modify] https://crrev.com/fbfe162dd52f7901535ceb70edf719ef4a692046/android_webview/glue/java/src/com/android/webview/chromium/WebViewChromiumFactoryProvider.java

Project Member

Comment 20 by bugdroid1@chromium.org, Jul 26 2016

The following revision refers to this bug:
  https://chrome-internal.googlesource.com/clank/internal/apps/+/85dc69cf31dbc427429f929b18867b0c88df27e0

commit 85dc69cf31dbc427429f929b18867b0c88df27e0
Author: boliu <boliu@chromium.org>
Date: Tue Jul 26 17:56:39 2016

Project Member

Comment 22 by bugdroid1@chromium.org, Jul 28 2016

The following revision refers to this bug:
  https://chrome-internal.googlesource.com/clank/internal/apps/+/96ea7367196502bd93ec7142901d1bc68efc1a4c

commit 96ea7367196502bd93ec7142901d1bc68efc1a4c
Author: boliu <boliu@chromium.org>
Date: Thu Jul 28 17:58:27 2016

Project Member

Comment 23 by bugdroid1@chromium.org, Jul 28 2016

The following revision refers to this bug:
  https://chrome-internal.googlesource.com/clank/internal/apps/+/058d33e7040e4e79696fd7e8c09da1e86a159d3a

commit 058d33e7040e4e79696fd7e8c09da1e86a159d3a
Author: Bo Liu <boliu@google.com>
Date: Thu Jul 28 20:12:38 2016

Comment 24 by boliu@chromium.org, Jul 28 2016

test is green now, but there's more stuff to fix..
Project Member

Comment 25 by bugdroid1@chromium.org, Jul 29 2016

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/755650c7085bb4c07bfa24112030340e2400727e

commit 755650c7085bb4c07bfa24112030340e2400727e
Author: boliu <boliu@chromium.org>
Date: Fri Jul 29 02:12:47 2016

Revert of aw: Fix FactoryProvider threading (patchset #3 id:40001 of https://codereview.chromium.org/2180423003/ )

Reason for revert:
Broke correct usage:  crbug.com/632547 

BUG= 632547 

Original issue's description:
> aw: Fix FactoryProvider threading
>
> Access thread-unsafe chromium classes on the UI thread only
>
> BUG= 630709 
>
> Committed: https://crrev.com/993fff8648f2701910b9efdbf1d35244fbf8ca73
> Cr-Commit-Position: refs/heads/master@{#408432}

TBR=torne@chromium.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG= 630709 

Review-Url: https://codereview.chromium.org/2197433002
Cr-Commit-Position: refs/heads/master@{#408557}

[modify] https://crrev.com/755650c7085bb4c07bfa24112030340e2400727e/android_webview/glue/BUILD.gn
[modify] https://crrev.com/755650c7085bb4c07bfa24112030340e2400727e/android_webview/glue/java/src/com/android/webview/chromium/WebViewChromium.java
[modify] https://crrev.com/755650c7085bb4c07bfa24112030340e2400727e/android_webview/glue/java/src/com/android/webview/chromium/WebViewChromiumFactoryProvider.java
[modify] https://crrev.com/755650c7085bb4c07bfa24112030340e2400727e/android_webview/tools/system_webview_shell/layout_tests/src/org/chromium/webview_shell/test/WebViewThreadTest.java

Project Member

Comment 26 by bugdroid1@chromium.org, Jul 29 2016

The following revision refers to this bug:
  https://chrome-internal.googlesource.com/clank/internal/apps/+/52c894ae9f35755a0a3fc682bcb4a852e436d3f3

commit 52c894ae9f35755a0a3fc682bcb4a852e436d3f3
Author: boliu <boliu@chromium.org>
Date: Fri Jul 29 02:12:47 2016

Project Member

Comment 27 by bugdroid1@chromium.org, Jul 29 2016

The following revision refers to this bug:
  https://chrome-internal.googlesource.com/clank/internal/apps/+/52c894ae9f35755a0a3fc682bcb4a852e436d3f3

commit 52c894ae9f35755a0a3fc682bcb4a852e436d3f3
Author: boliu <boliu@chromium.org>
Date: Fri Jul 29 02:12:47 2016

Project Member

Comment 28 by bugdroid1@chromium.org, Jul 29 2016

The following revision refers to this bug:
  https://chrome-internal.googlesource.com/clank/internal/apps/+/502c6b772c56e26a420576be518f9664027877a0

commit 502c6b772c56e26a420576be518f9664027877a0
Author: Bo Liu <boliu@google.com>
Date: Fri Jul 29 16:22:26 2016

Project Member

Comment 29 by bugdroid1@chromium.org, Jul 29 2016

The following revision refers to this bug:
  https://chrome-internal.googlesource.com/clank/internal/apps/+/998e64e0d6d65718f3bc5a7dec2ecba8037be09e

commit 998e64e0d6d65718f3bc5a7dec2ecba8037be09e
Author: Bo Liu <boliu@google.com>
Date: Fri Jul 29 16:22:54 2016

Project Member

Comment 31 by bugdroid1@chromium.org, Jul 29 2016

The following revision refers to this bug:
  https://chrome-internal.googlesource.com/clank/internal/apps/+/955a06f1f17b0a58122d50581162b3e545250868

commit 955a06f1f17b0a58122d50581162b3e545250868
Author: boliu <boliu@chromium.org>
Date: Fri Jul 29 16:28:46 2016

Project Member

Comment 33 by bugdroid1@chromium.org, Aug 1 2016

The following revision refers to this bug:
  https://chrome-internal.googlesource.com/clank/internal/apps/+/3cf7898fa4b5a20614f72169ff8660937e497d7f

commit 3cf7898fa4b5a20614f72169ff8660937e497d7f
Author: boliu <boliu@chromium.org>
Date: Mon Aug 01 16:42:38 2016

Comment 34 by boliu@chromium.org, Aug 26 2016

Status: Fixed (was: Assigned)

Sign in to add a comment