2009-12-16 Fumitoshi Ukai <ukai@chromium.org>
authorukai@chromium.org <ukai@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 17 Dec 2009 06:19:05 +0000 (06:19 +0000)
committerukai@chromium.org <ukai@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 17 Dec 2009 06:19:05 +0000 (06:19 +0000)
        Reviewed by Alexey Proskuryakov.

        Fix flakiness in WebSocket handshake console message.
        https://bugs.webkit.org/show_bug.cgi?id=32598

        In chromium, LayoutTests/websocket/tests/handshake-error.html is
        flaky, because it outputs the following console message several times:
          CONSOLE MESSAGE: line 0: Unexpected response code:101
        Update m_mode in WebSocketHandshake correctly: Once it finds
        error in handshake message, set m_mode to Failed and don't try
        reading handshake message again.  If handshake message is not yet
        fully received, set m_mode to Incomplete, so next didReceiveData()
        will try to check handshake message again.

        * websockets/WebSocketChannel.cpp:
        (WebCore::WebSocketChannel::didReceiveData):
        * websockets/WebSocketHandshake.cpp:
        (WebCore::WebSocketHandshake::readServerHandshake):

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

WebCore/ChangeLog
WebCore/websockets/WebSocketChannel.cpp
WebCore/websockets/WebSocketHandshake.cpp

index b068c87..8e5fc9c 100644 (file)
@@ -1,3 +1,24 @@
+2009-12-16  Fumitoshi Ukai  <ukai@chromium.org>
+
+        Reviewed by Alexey Proskuryakov.
+
+        Fix flakiness in WebSocket handshake console message.
+        https://bugs.webkit.org/show_bug.cgi?id=32598
+
+        In chromium, LayoutTests/websocket/tests/handshake-error.html is
+        flaky, because it outputs the following console message several times:
+          CONSOLE MESSAGE: line 0: Unexpected response code:101
+        Update m_mode in WebSocketHandshake correctly: Once it finds
+        error in handshake message, set m_mode to Failed and don't try
+        reading handshake message again.  If handshake message is not yet
+        fully received, set m_mode to Incomplete, so next didReceiveData()
+        will try to check handshake message again.
+
+        * websockets/WebSocketChannel.cpp:
+        (WebCore::WebSocketChannel::didReceiveData):
+        * websockets/WebSocketHandshake.cpp:
+        (WebCore::WebSocketHandshake::readServerHandshake):
+
 2009-12-16  Jon Honeycutt  <jhoneycutt@apple.com>
 
         MSAA: Accessibility role of text nodes is wrong
index 07b63d1..5c0f4c3 100644 (file)
@@ -150,7 +150,7 @@ void WebSocketChannel::didReceiveData(SocketStreamHandle* handle, const char* da
         handle->close();
         return;
     }
-    if (m_handshake.mode() != WebSocketHandshake::Connected) {
+    if (m_handshake.mode() == WebSocketHandshake::Incomplete) {
         int headerLength = m_handshake.readServerHandshake(m_buffer, m_bufferSize);
         if (headerLength <= 0)
             return;
@@ -179,6 +179,8 @@ void WebSocketChannel::didReceiveData(SocketStreamHandle* handle, const char* da
             return;
         LOG(Network, "remaining in read buf %ul", m_bufferSize);
     }
+    if (m_handshake.mode() != WebSocketHandshake::Connected)
+        return;
 
     const char* nextFrame = m_buffer;
     const char* p = m_buffer;
index c21d1d7..a568c2b 100644 (file)
@@ -220,14 +220,17 @@ int WebSocketHandshake::readServerHandshake(const char* header, size_t len)
             return -1;
         }
         if (code.isEmpty()) {
+            m_mode = Failed;
             m_context->addMessage(ConsoleDestination, JSMessageSource, LogMessageType, ErrorMessageLevel, "No response code found: " + String(header, len), 0, clientOrigin());
             return len;
         }
         LOG(Network, "response code: %s", code.utf8().data());
         if (code == "401") {
+            m_mode = Failed;
             m_context->addMessage(ConsoleDestination, JSMessageSource, LogMessageType, ErrorMessageLevel, "Authentication required, but not implemented yet.", 0, clientOrigin());
             return len;
         } else {
+            m_mode = Failed;
             m_context->addMessage(ConsoleDestination, JSMessageSource, LogMessageType, ErrorMessageLevel, "Unexpected response code:" + code, 0, clientOrigin());
             return len;
         }
@@ -237,18 +240,24 @@ int WebSocketHandshake::readServerHandshake(const char* header, size_t len)
 
     if (m_mode == Normal) {
         size_t headerSize = end - p;
-        if (headerSize < sizeof(webSocketUpgradeHeader) - 1)
+        if (headerSize < sizeof(webSocketUpgradeHeader) - 1) {
+            m_mode = Incomplete;
             return 0;
+        }
         if (memcmp(p, webSocketUpgradeHeader, sizeof(webSocketUpgradeHeader) - 1)) {
+            m_mode = Failed;
             m_context->addMessage(ConsoleDestination, JSMessageSource, LogMessageType, ErrorMessageLevel, "Bad Upgrade header: " + String(p, end - p), 0, clientOrigin());
             return p - header + sizeof(webSocketUpgradeHeader) - 1;
         }
         p += sizeof(webSocketUpgradeHeader) - 1;
 
         headerSize = end - p;
-        if (headerSize < sizeof(webSocketConnectionHeader) - 1)
+        if (headerSize < sizeof(webSocketConnectionHeader) - 1) {
+            m_mode = Incomplete;
             return -1;
+        }
         if (memcmp(p, webSocketConnectionHeader, sizeof(webSocketConnectionHeader) - 1)) {
+            m_mode = Failed;
             m_context->addMessage(ConsoleDestination, JSMessageSource, LogMessageType, ErrorMessageLevel, "Bad Connection header: " + String(p, end - p), 0, clientOrigin());
             return p - header + sizeof(webSocketConnectionHeader) - 1;
         }
@@ -257,6 +266,7 @@ int WebSocketHandshake::readServerHandshake(const char* header, size_t len)
 
     if (!strnstr(p, "\r\n\r\n", end - p)) {
         // Just hasn't been received fully yet.
+        m_mode = Incomplete;
         return -1;
     }
     HTTPHeaderMap headers;