Bug 138971 - [iOS] allocate volume view on the main thread
Summary: [iOS] allocate volume view on the main thread
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Media (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Eric Carlson
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2014-11-21 10:38 PST by Eric Carlson
Modified: 2015-06-18 10:00 PDT (History)
8 users (show)

See Also:


Attachments
Proposed patch. (3.68 KB, patch)
2014-11-21 11:07 PST, Eric Carlson
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Eric Carlson 2014-11-21 10:38:37 PST
The volume view used to check for wireless target availability should be allocated on the main thread.
Comment 1 Eric Carlson 2014-11-21 11:04:34 PST
rdar://problem/18016958
Comment 2 Eric Carlson 2014-11-21 11:07:51 PST
Created attachment 242053 [details]
Proposed patch.
Comment 3 WebKit Commit Bot 2014-11-21 13:22:35 PST
Comment on attachment 242053 [details]
Proposed patch.

Clearing flags on attachment: 242053

Committed r176471: <http://trac.webkit.org/changeset/176471>
Comment 4 WebKit Commit Bot 2014-11-21 13:22:42 PST
All reviewed patches have been landed.  Closing bug.
Comment 5 Eric Carlson 2014-11-24 20:42:09 PST
*** Bug 138961 has been marked as a duplicate of this bug. ***
Comment 6 Daniel 2014-11-27 07:07:21 PST
This fix is not good. It deadlocks the app if the main thread is doing something related to the web view, because at the time of .

We're getting this freeze quite often, and get different stacks in the main thread, ending with:

thread #1: tid = 0x10919d, 0x33473ba8 libsystem_kernel.dylib`__psynch_mutexwait + 24, queue = 'com.apple.main-thread', stop reason = signal SIGSTOP
  * frame #0: 0x33473ba8 libsystem_kernel.dylib`__psynch_mutexwait + 24
    frame #1: 0x334f103a libsystem_pthread.dylib`_pthread_mutex_lock + 394
    frame #2: 0x307fdf20 WebCore`_WebTryThreadLock(bool) + 44
    frame #3: 0x307fe736 WebCore`WebThreadLock + 82

While the WebThread will wait on dispatch_sync(dispatch_get_main_queue(), ...). The web thread is running, and locked so the main thread can't proceed to lock. The web thread can't proceed, with dispatch_sync, because the main thread is busy.

Try using dispatch_async instead. This should do the trick if the _volumeView is not going to be used immediately in the WebThread.
Comment 7 Eric Carlson 2014-12-01 21:43:09 PST
(In reply to comment #6)
> This fix is not good. It deadlocks the app if the main thread is doing
> something related to the web view, because at the time of .
> 
> We're getting this freeze quite often, and get different stacks in the main
> thread, ending with:
> 
> thread #1: tid = 0x10919d, 0x33473ba8
> libsystem_kernel.dylib`__psynch_mutexwait + 24, queue =
> 'com.apple.main-thread', stop reason = signal SIGSTOP
>   * frame #0: 0x33473ba8 libsystem_kernel.dylib`__psynch_mutexwait + 24
>     frame #1: 0x334f103a libsystem_pthread.dylib`_pthread_mutex_lock + 394
>     frame #2: 0x307fdf20 WebCore`_WebTryThreadLock(bool) + 44
>     frame #3: 0x307fe736 WebCore`WebThreadLock + 82
> 
> While the WebThread will wait on dispatch_sync(dispatch_get_main_queue(),
> ...). The web thread is running, and locked so the main thread can't proceed
> to lock. The web thread can't proceed, with dispatch_sync, because the main
> thread is busy.
> 
> Try using dispatch_async instead. This should do the trick if the
> _volumeView is not going to be used immediately in the WebThread.

Thank you for the information. 

Please feel free to submit patches if you have suggestions for changes.
Comment 8 Ian 2015-03-23 14:19:05 PDT
UIWebView frequently crashes on iOS because of this bug and the proposed patch does not fix the problem.
A reproducible example has been provided with rdar://problem/18609955

The allocateVolumeView method checks for isMainThread() which is implemented as: (isWebThread() || pthread_main_np())
Since this is called from the web thread, isMainThread returns true.

Also, MPVolumeView gets allocated twice in the case where isMainThread() is false. Once on the main thread and then another time on the background thread (which is what we are trying to avoid here).