Remove RELEASE_ASSERT added in r230875.
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 25 Jun 2018 23:56:01 +0000 (23:56 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 25 Jun 2018 23:56:01 +0000 (23:56 +0000)
<rdar://problem/40860061> and https://bugs.webkit.org/show_bug.cgi?id=187022

Reviewed by Brent Fulgham.

There's actually more than one way for a network session to be destroyed, and that can happen
asynchronously and unpredictably.

And the request to start up a WebSocket and do its handshake is also asynchronous and unpredictable

It's an expected race.

If the NetworkStorageSession cannot be found then the WebSocket handshake should just fail.

* platform/network/SocketStreamHandleImpl.cpp:
(WebCore::cookieDataForHandshake): If the NetworkStorageSession cannot be found, return std::nullopt.
(WebCore::SocketStreamHandleImpl::platformSendHandshake): If the cookieData is null, fail the handshake.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@233183 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/platform/network/SocketStreamHandleImpl.cpp

index 4a0cc6e..ee8b94e 100644 (file)
@@ -1,3 +1,23 @@
+2018-06-25  Brady Eidson  <beidson@apple.com>
+
+        Remove RELEASE_ASSERT added in r230875.
+        <rdar://problem/40860061> and https://bugs.webkit.org/show_bug.cgi?id=187022
+
+        Reviewed by Brent Fulgham.
+
+        There's actually more than one way for a network session to be destroyed, and that can happen
+        asynchronously and unpredictably.
+
+        And the request to start up a WebSocket and do its handshake is also asynchronous and unpredictable
+        It's an expected race.
+
+        If the NetworkStorageSession cannot be found then the WebSocket handshake should just fail.
+
+        * platform/network/SocketStreamHandleImpl.cpp:
+        (WebCore::cookieDataForHandshake): If the NetworkStorageSession cannot be found, return std::nullopt.
+        (WebCore::SocketStreamHandleImpl::platformSendHandshake): If the cookieData is null, fail the handshake.
+
 2018-06-25  Wenson Hsieh  <wenson_hsieh@apple.com>
 
         [iPad apps on macOS] Web process crashes when attempting to play embedded YouTube video in News
index 69b4182..759d63a 100644 (file)
@@ -77,16 +77,17 @@ static size_t removeTerminationCharacters(const uint8_t* data, size_t dataLength
     return dataLength - 2;
 }
 
-static std::pair<Vector<uint8_t>, bool> cookieDataForHandshake(const CookieRequestHeaderFieldProxy& headerFieldProxy)
+static std::optional<std::pair<Vector<uint8_t>, bool>> cookieDataForHandshake(const CookieRequestHeaderFieldProxy& headerFieldProxy)
 {
     auto networkStorageSession = NetworkStorageSession::storageSession(headerFieldProxy.sessionID);
-    RELEASE_ASSERT(networkStorageSession);
-
+    if (!networkStorageSession)
+        return std::nullopt;
+    
     String cookieDataString;
     bool secureCookiesAccessed = false;
     std::tie(cookieDataString, secureCookiesAccessed) = WebCore::cookieRequestHeaderFieldValue(*networkStorageSession, headerFieldProxy);
     if (cookieDataString.isEmpty())
-        return { { }, secureCookiesAccessed };
+        return std::pair<Vector<uint8_t>, bool> { { }, secureCookiesAccessed };
 
     CString cookieData = cookieDataString.utf8();
 
@@ -94,7 +95,7 @@ static std::pair<Vector<uint8_t>, bool> cookieDataForHandshake(const CookieReque
     data.append(cookieData.data(), cookieData.length());
     data.appendVector(Vector<uint8_t>({ '\r', '\n', '\r', '\n' }));
 
-    return { data, secureCookiesAccessed };
+    return std::pair<Vector<uint8_t>, bool> { data, secureCookiesAccessed };
 }
 
 void SocketStreamHandleImpl::platformSendHandshake(const uint8_t* data, size_t length, const std::optional<CookieRequestHeaderFieldProxy>& headerFieldProxy, Function<void(bool, bool)>&& completionHandler)
@@ -103,7 +104,13 @@ void SocketStreamHandleImpl::platformSendHandshake(const uint8_t* data, size_t l
     bool secureCookiesAccessed = false;
 
     if (headerFieldProxy) {
-        std::tie(cookieData, secureCookiesAccessed) = cookieDataForHandshake(headerFieldProxy.value());
+        auto cookieDataFromNetworkSession = cookieDataForHandshake(headerFieldProxy.value());
+        if (!cookieDataFromNetworkSession) {
+            completionHandler(false, false);
+            return;
+        }
+
+        std::tie(cookieData, secureCookiesAccessed) = *cookieDataFromNetworkSession;
         if (cookieData.size())
             length = removeTerminationCharacters(data, length);
     }