Title: [169051] trunk/Source/WebKit2
Revision
169051
Author
[email protected]
Date
2014-05-19 11:00:10 -0700 (Mon, 19 May 2014)

Log Message

[WebKit2] Wake up threads blocked in waitForAndDispatchImmediately() if we lose our connection
https://bugs.webkit.org/show_bug.cgi?id=133010

Reviewed by Geoffrey Garen.

If a thread is blocked on m_waitForMessageCondition and we lose our connection, treat that like we do a timeout.

* Platform/IPC/Connection.cpp:
(IPC::Connection::Connection):
(IPC::Connection::waitForMessage):
(IPC::Connection::connectionDidClose):
* Platform/IPC/Connection.h:

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (169050 => 169051)


--- trunk/Source/WebKit2/ChangeLog	2014-05-19 17:50:49 UTC (rev 169050)
+++ trunk/Source/WebKit2/ChangeLog	2014-05-19 18:00:10 UTC (rev 169051)
@@ -1,3 +1,18 @@
+2014-05-16  Andy Estes  <[email protected]>
+
+        [WebKit2] Wake up threads blocked in waitForAndDispatchImmediately() if we lose our connection
+        https://bugs.webkit.org/show_bug.cgi?id=133010
+
+        Reviewed by Geoffrey Garen.
+
+        If a thread is blocked on m_waitForMessageCondition and we lose our connection, treat that like we do a timeout.
+
+        * Platform/IPC/Connection.cpp:
+        (IPC::Connection::Connection):
+        (IPC::Connection::waitForMessage):
+        (IPC::Connection::connectionDidClose):
+        * Platform/IPC/Connection.h:
+
 2014-05-19  Mark Rowe  <[email protected]>
 
         Build fix after r169023.

Modified: trunk/Source/WebKit2/Platform/IPC/Connection.cpp (169050 => 169051)


--- trunk/Source/WebKit2/Platform/IPC/Connection.cpp	2014-05-19 17:50:49 UTC (rev 169050)
+++ trunk/Source/WebKit2/Platform/IPC/Connection.cpp	2014-05-19 18:00:10 UTC (rev 169051)
@@ -225,6 +225,7 @@
     , m_inDispatchMessageCount(0)
     , m_inDispatchMessageMarkedDispatchWhenWaitingForSyncReplyCount(0)
     , m_didReceiveInvalidMessage(false)
+    , m_messageWaitingInterruptedByClosedConnection(false)
     , m_syncMessageState(SyncMessageState::getOrCreate(clientRunLoop))
     , m_shouldWaitForSyncReplies(true)
 {
@@ -413,10 +414,16 @@
         }
 
         // Now we wait.
-        if (m_waitForMessageCondition.wait_for(lock, timeout) == std::cv_status::timeout) {
-            // We timed out, now remove the pending wait.
+        std::cv_status status = m_waitForMessageCondition.wait_for(lock, timeout);
+        if (status == std::cv_status::timeout || m_messageWaitingInterruptedByClosedConnection) {
+            // We timed out or lost our connection, now remove the pending wait.
             m_waitForMessageMap.remove(messageAndDestination);
 
+            // If there are no more waiters, reset m_messageWaitingInterruptedByClosedConnection while we already hold
+            // the necessary lock in case the connection is later reopened.
+            if (m_waitForMessageMap.isEmpty())
+                m_messageWaitingInterruptedByClosedConnection = false;
+
             break;
         }
     }
@@ -676,6 +683,12 @@
             iter->value->semaphore.signal();
     }
 
+    {
+        std::lock_guard<std::mutex> lock(m_waitForMessageMutex);
+        m_messageWaitingInterruptedByClosedConnection = true;
+    }
+    m_waitForMessageCondition.notify_all();
+
     if (m_didCloseOnConnectionWorkQueueCallback)
         m_didCloseOnConnectionWorkQueueCallback(this);
 

Modified: trunk/Source/WebKit2/Platform/IPC/Connection.h (169050 => 169051)


--- trunk/Source/WebKit2/Platform/IPC/Connection.h	2014-05-19 17:50:49 UTC (rev 169050)
+++ trunk/Source/WebKit2/Platform/IPC/Connection.h	2014-05-19 18:00:10 UTC (rev 169051)
@@ -247,6 +247,7 @@
     
     std::condition_variable m_waitForMessageCondition;
     std::mutex m_waitForMessageMutex;
+    bool m_messageWaitingInterruptedByClosedConnection;
     HashMap<std::pair<std::pair<StringReference, StringReference>, uint64_t>, std::unique_ptr<MessageDecoder>> m_waitForMessageMap;
 
     // Represents a sync request for which we're waiting on a reply.
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to