Title: [253203] trunk
Revision
253203
Author
[email protected]
Date
2019-12-06 01:25:22 -0800 (Fri, 06 Dec 2019)

Log Message

Protect WebRTC network monitoring to wait forever in edge cases
https://bugs.webkit.org/show_bug.cgi?id=204846
Source/WebKit:

Reviewed by Eric Carlson.

We were limiting the number of IPC message sent to network process by only sending the start monitoring event for the first client.
The issue is that, if network process crashes for instance while having not yet given the list of networks, all clients will be hanging
waiting for the completion of network list.
We are now sending an IPC message for every client and the network process will ignore the ones that are not useful.
In addition, in case of network process crash, we send a signal that network list has changed to make sure clients will never hang.
They might still fail connecting, which is ok since network process crashed.

Test: webrtc/datachannel/gather-candidates-networkprocess-crash.html

* NetworkProcess/webrtc/NetworkRTCMonitor.cpp:
(WebKit::NetworkRTCMonitor::startUpdatingIfNeeded):
* NetworkProcess/webrtc/NetworkRTCMonitor.h:
* NetworkProcess/webrtc/NetworkRTCMonitor.messages.in:
* WebProcess/Network/webrtc/LibWebRTCNetwork.h:
(WebKit::LibWebRTCNetwork::networkProcessCrashed):
* WebProcess/Network/webrtc/WebRTCMonitor.cpp:
(WebKit::WebRTCMonitor::StartUpdating):
(WebKit::WebRTCMonitor::StopUpdating):
(WebKit::WebRTCMonitor::networksChanged):
(WebKit::WebRTCMonitor::networkProcessCrashed):
* WebProcess/Network/webrtc/WebRTCMonitor.h:
* WebProcess/WebProcess.cpp:
(WebKit::WebProcess::networkProcessConnectionClosed):

LayoutTests:

<rdar://problem/57618773>

Reviewed by Eric Carlson.

* webrtc/datachannel/gather-candidates-networkprocess-crash-expected.txt: Added.
* webrtc/datachannel/gather-candidates-networkprocess-crash.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (253202 => 253203)


--- trunk/LayoutTests/ChangeLog	2019-12-06 09:24:40 UTC (rev 253202)
+++ trunk/LayoutTests/ChangeLog	2019-12-06 09:25:22 UTC (rev 253203)
@@ -1,3 +1,14 @@
+2019-12-06  youenn fablet  <[email protected]>
+
+        Protect WebRTC network monitoring to wait forever in edge cases
+        https://bugs.webkit.org/show_bug.cgi?id=204846
+        <rdar://problem/57618773>
+
+        Reviewed by Eric Carlson.
+
+        * webrtc/datachannel/gather-candidates-networkprocess-crash-expected.txt: Added.
+        * webrtc/datachannel/gather-candidates-networkprocess-crash.html: Added.
+
 2019-12-05  Yury Semikhatsky  <[email protected]>
 
         Web Inspector: http/tests/inspector/target/pause-on-inline-debugger-statement.html is crashing in debug

Added: trunk/LayoutTests/webrtc/datachannel/gather-candidates-networkprocess-crash-expected.txt (0 => 253203)


--- trunk/LayoutTests/webrtc/datachannel/gather-candidates-networkprocess-crash-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/webrtc/datachannel/gather-candidates-networkprocess-crash-expected.txt	2019-12-06 09:25:22 UTC (rev 253203)
@@ -0,0 +1,3 @@
+
+PASS Gathering ICE candidates from a data channel while network process is crashing 
+

Added: trunk/LayoutTests/webrtc/datachannel/gather-candidates-networkprocess-crash.html (0 => 253203)


--- trunk/LayoutTests/webrtc/datachannel/gather-candidates-networkprocess-crash.html	                        (rev 0)
+++ trunk/LayoutTests/webrtc/datachannel/gather-candidates-networkprocess-crash.html	2019-12-06 09:25:22 UTC (rev 253203)
@@ -0,0 +1,28 @@
+<!doctype html>
+<html>
+  <head>
+    <meta charset="utf-8">
+    <title>Testing ICE candidate filtering when using data channel</title>
+    <script src=""
+    <script src=""
+  </head>
+  <body>
+    <script>
+promise_test(async (test) => {
+    var counter = 0;
+    var pc = new RTCPeerConnection();
+    pc.createDataChannel('sendDataChannel');
+
+    const iceCandidatePromise = new Promise(r => pc._onicecandidate_ = r);
+
+    const offer = await pc.createOffer();
+    pc.setLocalDescription(offer);
+    // This test is a bit racy, we are trying to have network process crash between the time it receives a monitor start request and the time it answers that request.
+    if (window.testRunner && testRunner.terminateNetworkProcess)
+       setTimeout(() => testRunner.terminateNetworkProcess(), 0);
+
+    await iceCandidatePromise;
+}, "Gathering ICE candidates from a data channel while network process is crashing");
+    </script>
+  </body>
+</html>

Modified: trunk/Source/WebCore/platform/mediastream/libwebrtc/LibWebRTCProvider.cpp (253202 => 253203)


--- trunk/Source/WebCore/platform/mediastream/libwebrtc/LibWebRTCProvider.cpp	2019-12-06 09:24:40 UTC (rev 253202)
+++ trunk/Source/WebCore/platform/mediastream/libwebrtc/LibWebRTCProvider.cpp	2019-12-06 09:25:22 UTC (rev 253203)
@@ -217,6 +217,11 @@
     delete data;
 }
 
+bool LibWebRTCProvider::hasWebRTCThreads()
+{
+    return !!staticFactoryAndThreads().networkThread;
+}
+
 void LibWebRTCProvider::callOnWebRTCNetworkThread(Function<void()>&& callback)
 {
     PeerConnectionFactoryAndThreads& threads = staticFactoryAndThreads();

Modified: trunk/Source/WebCore/platform/mediastream/libwebrtc/LibWebRTCProvider.h (253202 => 253203)


--- trunk/Source/WebCore/platform/mediastream/libwebrtc/LibWebRTCProvider.h	2019-12-06 09:24:40 UTC (rev 253202)
+++ trunk/Source/WebCore/platform/mediastream/libwebrtc/LibWebRTCProvider.h	2019-12-06 09:25:22 UTC (rev 253203)
@@ -98,6 +98,7 @@
     // FIXME: Make these methods not static.
     static void callOnWebRTCNetworkThread(Function<void()>&&);
     static void callOnWebRTCSignalingThread(Function<void()>&&);
+    static bool hasWebRTCThreads();
 
     // Used for mock testing
     void setPeerConnectionFactory(rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface>&&);

Modified: trunk/Source/WebKit/ChangeLog (253202 => 253203)


--- trunk/Source/WebKit/ChangeLog	2019-12-06 09:24:40 UTC (rev 253202)
+++ trunk/Source/WebKit/ChangeLog	2019-12-06 09:25:22 UTC (rev 253203)
@@ -1,5 +1,36 @@
 2019-12-06  youenn fablet  <[email protected]>
 
+        Protect WebRTC network monitoring to wait forever in edge cases
+        https://bugs.webkit.org/show_bug.cgi?id=204846
+
+        Reviewed by Eric Carlson.
+
+        We were limiting the number of IPC message sent to network process by only sending the start monitoring event for the first client.
+        The issue is that, if network process crashes for instance while having not yet given the list of networks, all clients will be hanging
+        waiting for the completion of network list.
+        We are now sending an IPC message for every client and the network process will ignore the ones that are not useful.
+        In addition, in case of network process crash, we send a signal that network list has changed to make sure clients will never hang.
+        They might still fail connecting, which is ok since network process crashed.
+
+        Test: webrtc/datachannel/gather-candidates-networkprocess-crash.html
+
+        * NetworkProcess/webrtc/NetworkRTCMonitor.cpp:
+        (WebKit::NetworkRTCMonitor::startUpdatingIfNeeded):
+        * NetworkProcess/webrtc/NetworkRTCMonitor.h:
+        * NetworkProcess/webrtc/NetworkRTCMonitor.messages.in:
+        * WebProcess/Network/webrtc/LibWebRTCNetwork.h:
+        (WebKit::LibWebRTCNetwork::networkProcessCrashed):
+        * WebProcess/Network/webrtc/WebRTCMonitor.cpp:
+        (WebKit::WebRTCMonitor::StartUpdating):
+        (WebKit::WebRTCMonitor::StopUpdating):
+        (WebKit::WebRTCMonitor::networksChanged):
+        (WebKit::WebRTCMonitor::networkProcessCrashed):
+        * WebProcess/Network/webrtc/WebRTCMonitor.h:
+        * WebProcess/WebProcess.cpp:
+        (WebKit::WebProcess::networkProcessConnectionClosed):
+
+2019-12-06  youenn fablet  <[email protected]>
+
         Output libwebrtc logging from Network Process as release logging
         https://bugs.webkit.org/show_bug.cgi?id=204853
 

Modified: trunk/Source/WebKit/NetworkProcess/webrtc/NetworkRTCMonitor.cpp (253202 => 253203)


--- trunk/Source/WebKit/NetworkProcess/webrtc/NetworkRTCMonitor.cpp	2019-12-06 09:24:40 UTC (rev 253202)
+++ trunk/Source/WebKit/NetworkProcess/webrtc/NetworkRTCMonitor.cpp	2019-12-06 09:25:22 UTC (rev 253203)
@@ -40,8 +40,11 @@
     ASSERT(!m_manager);
 }
 
-void NetworkRTCMonitor::startUpdating()
+void NetworkRTCMonitor::startUpdatingIfNeeded()
 {
+    if (m_isStarted)
+        return;
+
     m_isStarted = true;
     m_rtcProvider.callOnRTCNetworkThread([this]() {
         m_manager = makeUniqueWithoutFastMallocCheck<rtc::BasicNetworkManager>();

Modified: trunk/Source/WebKit/NetworkProcess/webrtc/NetworkRTCMonitor.h (253202 => 253203)


--- trunk/Source/WebKit/NetworkProcess/webrtc/NetworkRTCMonitor.h	2019-12-06 09:24:40 UTC (rev 253202)
+++ trunk/Source/WebKit/NetworkProcess/webrtc/NetworkRTCMonitor.h	2019-12-06 09:25:22 UTC (rev 253203)
@@ -51,7 +51,7 @@
     bool isStarted() const { return m_isStarted; }
 
 private:
-    void startUpdating();
+    void startUpdatingIfNeeded();
 
     void onNetworksChanged();
 

Modified: trunk/Source/WebKit/NetworkProcess/webrtc/NetworkRTCMonitor.messages.in (253202 => 253203)


--- trunk/Source/WebKit/NetworkProcess/webrtc/NetworkRTCMonitor.messages.in	2019-12-06 09:24:40 UTC (rev 253202)
+++ trunk/Source/WebKit/NetworkProcess/webrtc/NetworkRTCMonitor.messages.in	2019-12-06 09:25:22 UTC (rev 253203)
@@ -23,7 +23,7 @@
 #if USE(LIBWEBRTC)
 
 messages -> NetworkRTCMonitor NotRefCounted {
-    void StartUpdating()
+    void StartUpdatingIfNeeded()
     void StopUpdating()
 }
 

Modified: trunk/Source/WebKit/WebProcess/Network/webrtc/LibWebRTCNetwork.h (253202 => 253203)


--- trunk/Source/WebKit/WebProcess/Network/webrtc/LibWebRTCNetwork.h	2019-12-06 09:24:40 UTC (rev 253202)
+++ trunk/Source/WebKit/WebProcess/Network/webrtc/LibWebRTCNetwork.h	2019-12-06 09:25:22 UTC (rev 253203)
@@ -42,6 +42,8 @@
 public:
     LibWebRTCNetwork() = default;
 
+    void networkProcessCrashed();
+
 #if USE(LIBWEBRTC)
     WebRTCMonitor& monitor() { return m_webNetworkMonitor; }
     LibWebRTCSocketFactory& socketFactory() { return m_socketFactory; }
@@ -66,4 +68,11 @@
 #endif
 };
 
+inline void LibWebRTCNetwork::networkProcessCrashed()
+{
+#if USE(LIBWEBRTC)
+    m_webNetworkMonitor.networkProcessCrashed();
+#endif
+}
+
 } // namespace WebKit

Modified: trunk/Source/WebKit/WebProcess/Network/webrtc/WebRTCMonitor.cpp (253202 => 253203)


--- trunk/Source/WebKit/WebProcess/Network/webrtc/WebRTCMonitor.cpp	2019-12-06 09:24:40 UTC (rev 253202)
+++ trunk/Source/WebKit/WebProcess/Network/webrtc/WebRTCMonitor.cpp	2019-12-06 09:25:22 UTC (rev 253203)
@@ -28,6 +28,7 @@
 
 #if USE(LIBWEBRTC)
 
+#include "Logging.h"
 #include "NetworkConnectionToWebProcessMessages.h"
 #include "NetworkProcessConnection.h"
 #include "NetworkRTCMonitorMessages.h"
@@ -47,29 +48,29 @@
 
 void WebRTCMonitor::StartUpdating()
 {
-    if (m_clientCount) {
-        // Need to signal new client that we already have the network list, let's do it asynchronously
-        if (m_receivedNetworkList) {
-            WebCore::LibWebRTCProvider::callOnWebRTCNetworkThread([this] {
-                SignalNetworksChanged();
-            });
-        }
-    } else {
-        m_receivedNetworkList = false;
-        sendOnMainThread([](IPC::Connection& connection) {
-            connection.send(Messages::NetworkRTCMonitor::StartUpdating(), 0);
+    RELEASE_LOG(WebRTC, "WebRTCMonitor::StartUpdating");
+    if (m_receivedNetworkList) {
+        WebCore::LibWebRTCProvider::callOnWebRTCNetworkThread([this] {
+            SignalNetworksChanged();
         });
     }
+
+    sendOnMainThread([](IPC::Connection& connection) {
+        RELEASE_LOG(WebRTC, "WebRTCMonitor asks network process to start updating");
+        connection.send(Messages::NetworkRTCMonitor::StartUpdatingIfNeeded(), 0);
+    });
     ++m_clientCount;
 }
 
 void WebRTCMonitor::StopUpdating()
 {
+    RELEASE_LOG(WebRTC, "WebRTCMonitor::StopUpdating");
     ASSERT(m_clientCount);
     if (--m_clientCount)
         return;
 
     sendOnMainThread([](IPC::Connection& connection) {
+        RELEASE_LOG(WebRTC, "WebRTCMonitor asks network process to stop updating");
         connection.send(Messages::NetworkRTCMonitor::StopUpdating(), 0);
     });
 }
@@ -76,6 +77,7 @@
 
 void WebRTCMonitor::networksChanged(const Vector<RTCNetwork>& networks, const RTCNetwork::IPAddress& ipv4, const RTCNetwork::IPAddress& ipv6)
 {
+    RELEASE_LOG(WebRTC, "WebRTCMonitor::networksChanged");
     // No need to protect 'this' as it has the lifetime of LibWebRTC which has the lifetime of the web process.
     WebCore::LibWebRTCProvider::callOnWebRTCNetworkThread([this, networks, ipv4, ipv6] {
         std::vector<rtc::Network*> networkList(networks.size());
@@ -94,6 +96,18 @@
     });
 }
 
+void WebRTCMonitor::networkProcessCrashed()
+{
+    m_receivedNetworkList = false;
+    if (!WebCore::LibWebRTCProvider::hasWebRTCThreads())
+        return;
+
+    // In case we have clients waiting for networksChanged, we call SignalNetworksChanged to make sure they do not wait for nothing.    
+    WebCore::LibWebRTCProvider::callOnWebRTCNetworkThread([this] {
+        SignalNetworksChanged();
+    });
+}
+
 } // namespace WebKit
 
 #endif // USE(LIBWEBRTC)

Modified: trunk/Source/WebKit/WebProcess/Network/webrtc/WebRTCMonitor.h (253202 => 253203)


--- trunk/Source/WebKit/WebProcess/Network/webrtc/WebRTCMonitor.h	2019-12-06 09:24:40 UTC (rev 253202)
+++ trunk/Source/WebKit/WebProcess/Network/webrtc/WebRTCMonitor.h	2019-12-06 09:25:22 UTC (rev 253203)
@@ -44,6 +44,7 @@
 public:
     WebRTCMonitor() = default;
 
+    void networkProcessCrashed();
     void didReceiveMessage(IPC::Connection&, IPC::Decoder&);
 
 private:

Modified: trunk/Source/WebKit/WebProcess/WebProcess.cpp (253202 => 253203)


--- trunk/Source/WebKit/WebProcess/WebProcess.cpp	2019-12-06 09:24:40 UTC (rev 253202)
+++ trunk/Source/WebKit/WebProcess/WebProcess.cpp	2019-12-06 09:25:22 UTC (rev 253203)
@@ -1244,6 +1244,9 @@
     WebSocketStream::networkProcessCrashed();
     m_webSocketChannelManager.networkProcessCrashed();
 
+    if (m_libWebRTCNetwork)
+        m_libWebRTCNetwork->networkProcessCrashed();
+
     for (auto& page : m_pageMap.values()) {
         page->stopAllURLSchemeTasks();
 #if ENABLE(APPLE_PAY)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to