<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>51351</bug_id>
          
          <creation_ts>2010-12-20 13:21:43 -0800</creation_ts>
          <short_desc>UI process should respond to synchronous messages from the web process on a non-main thread by default</short_desc>
          <delta_ts>2015-06-18 14:56:20 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>WebKit2</component>
          <version>528+ (Nightly build)</version>
          <rep_platform>All</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>INVALID</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          <blocked>51352</blocked>
          <everconfirmed>1</everconfirmed>
          <reporter name="Adam Roben (:aroben)">aroben</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>andersca</cc>
    
    <cc>sam</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>324536</commentid>
    <comment_count>0</comment_count>
    <who name="Adam Roben (:aroben)">aroben</who>
    <bug_when>2010-12-20 13:21:43 -0800</bug_when>
    <thetext>The UI process currently responds to both synchronous and asynchronous messages from the web process on the main thread. Messages are received on the CoreIPC::Connection&apos;s work queue and then forwarded to the main thread for processing.

This can cause deadlocks on Windows when windowed plugins are involved. For example, take the case of a YouTube video embedded into some third party web page. Here&apos;s what happens:

Web process:
Clicking on the plugin opens a new window so that it can be navigated to the video&apos;s YouTube page. In order to open the new window, the web process sends a synchronous WebPageProxy::CreateNewPage message and blocks its main thread to wait for the reply.

UI process:
The UI process receives the WebPageProxy::CreateNewPage message, and ends up calling through to WKPageUIClient::createNewPage. The client app responds to this callback by creating a new window and selecting it. Selecting the new window causes the plugin to lose focus. As part of unfocusing the plugin, Windows sends the plugin a synchronous WM_KILLFOCUS message to it and blocks the main thread while waiting for the message to be handled.

Since the web process&apos;s main thread is still blocked waiting for the reply to WebPageProxy::CreateNewPage, it can&apos;t process the WM_KILLFOCUS message, so the two processes deadlock. (The web process is waiting for CreateNewPage to be handled, and the UI process is waiting for WM_KILLFOCUS to be handled.)

We should make the UI process respond to synchronous messages on a non-main thread by default. We&apos;ll want to continue making WK2 client callbacks (e.g., WKPageUIClient::createNewPage) on the main thread, but those need to happen asynchronously to avoid deadlocks.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>324538</commentid>
    <comment_count>1</comment_count>
    <who name="Adam Roben (:aroben)">aroben</who>
    <bug_when>2010-12-20 13:24:13 -0800</bug_when>
    <thetext>(In reply to comment #0)
&gt; We should make the UI process respond to synchronous messages on a non-main thread by default.

Messages that end up displaying UI still need to be processed on the main thread. Fixing deadlocks with those messages is covered by bug 51352.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>324539</commentid>
    <comment_count>2</comment_count>
    <who name="Adam Roben (:aroben)">aroben</who>
    <bug_when>2010-12-20 13:24:46 -0800</bug_when>
    <thetext>&lt;rdar://problem/8790535&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>340616</commentid>
    <comment_count>3</comment_count>
    <who name="Adam Roben (:aroben)">aroben</who>
    <bug_when>2011-01-26 17:19:34 -0800</bug_when>
    <thetext>We&apos;ve decided to see if we can get away without this. We&apos;ll still have to fix bug 51352.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>340673</commentid>
    <comment_count>4</comment_count>
    <who name="Adam Roben (:aroben)">aroben</who>
    <bug_when>2011-01-26 18:08:23 -0800</bug_when>
    <thetext>(In reply to comment #3)
&gt; We&apos;ve decided to see if we can get away without this. We&apos;ll still have to fix bug 51352.

Anders and I just talked some more and realized that we will probably need to fix this eventually. Consider the following situation:

Web process:
Sends some asynchronous messages to the UI process, then sends a synchronous message (that doesn&apos;t present UI and thus is not covered by bug 51352, e.g., GetToolbarsAreVisible), and blocks waiting for a reply.

UI process:
While processing one of the asynchronous messages, touches the window hierarchy, resulting in a synchronous message to the web process.

So we&apos;ve ended up in a deadlock again even if bug 51352 is fixed.

Our plan is threefold:
1) Make the web process spin a run loop while waiting for a reply to any synchronous message, not just those that end up presenting UI in the UI process.
2) Add a test mode to WebKit2 that exercises the reentrancy that spinning a nested run loop enables.
3) Eventually change WebKit2 only to spin a run loop while waiting for a reply to a synchronous message that will present UI, and move all other synchronous message handling to a non-main thread, as described in comment 1.

If the testing from (2) uncovers many intractable issues, we may do (3) sooner rather than later.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>340677</commentid>
    <comment_count>5</comment_count>
    <who name="Adam Roben (:aroben)">aroben</who>
    <bug_when>2011-01-26 18:11:14 -0800</bug_when>
    <thetext>Whoops, forgot to reopen the bug.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>349280</commentid>
    <comment_count>6</comment_count>
    <who name="Adam Roben (:aroben)">aroben</who>
    <bug_when>2011-02-10 12:37:57 -0800</bug_when>
    <thetext>The deadlocks caused by this bug are even more frequent now that decidePolicyForNavigationAction is synchronous.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>383198</commentid>
    <comment_count>7</comment_count>
    <who name="Adam Roben (:aroben)">aroben</who>
    <bug_when>2011-04-11 09:07:15 -0700</bug_when>
    <thetext>(In reply to comment #4)
&gt; 1) Make the web process spin a run loop while waiting for a reply to any synchronous message, not just those that end up presenting UI in the UI process.

This is now bug 58239.

&gt; 2) Add a test mode to WebKit2 that exercises the reentrancy that spinning a nested run loop enables.

This is bug 53218.

&gt; 3) Eventually change WebKit2 only to spin a run loop while waiting for a reply to a synchronous message that will present UI, and move all other synchronous message handling to a non-main thread, as described in comment 1.

This is bug 51352.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1103044</commentid>
    <comment_count>8</comment_count>
    <who name="Anders Carlsson">andersca</who>
    <bug_when>2015-06-18 14:56:20 -0700</bug_when>
    <thetext>We got rid of WK2 for Windows so this no longer applies.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>