Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-56363

Client timeout leads to unresponsive Qt SSL Websocket server

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: P3: Somewhat important P3: Somewhat important
    • None
    • 5.3.2
    • WebSockets
    • None
    • Windows 7, Google Chrome, OpenSSL self-signed certificate
    • Can't be reproduced in 5.7 anymore

      I discovered the following behaviour with the Qt SSL Websocket Server. The following example should be fully reproducible. I used OpenSSL to generate a self signed certificate. The problem only occurs with Google Chrome, because e.g. in IE I don't get the timeout message on the client after that time.

      .) The attached example program is completely based on the official ssl websocket example: http://doc.qt.io/qt-5/qtwebsockets-sslechoserver-example.html

      The only difference is the QThread::sleep(90); command in the SslEchoServer::processTextMessage method to simulate a busy thread, which also could occur when large websocket messages are received.

      .) SLOT processTextMessage:

      #include <QThread>
      
      void SslEchoServer::processTextMessage(QString message)
      {
          QWebSocket *pClient = qobject_cast<QWebSocket *>(sender());
          if (pClient)
          {
              qDebug() << "Received";
              qDebug() << message;
      
              qDebug() << "Sleeping...";
              QThread::sleep(90);
              qDebug() << "Wake up...";
          }
      }
      

      At first I describe the steps I needed to get the official ssl websocket server example running.

      .) To get the example program running I generated self-signed-certificates (ssl_test.zip) with openssl, which have to be unpacked into some folder. There are many tutorials available how to generate them (e.g. https://blog.didierstevens.com/2015/03/30/howto-make-your-own-cert-with-openssl-on-windows/)

      The paths of the cert and key/pem files have to be adapted at SslEchoServer::SslEchoServer(quint16 port, QObject *parent).

      .) Set up the websocket client html page, which is included in websocket_ssl_test.zip. Change your IP address there. I got the example only working when the server and client where running on different machines btw., but this could be a specific problem of my environment.

      (see also http://doc.qt.io/qt-5/qtwebsockets-sslechoserver-sslechoclient-html.html)

      .) Make sure that the windows firewall is not blocking the websocket port (4433 in this example), so probably you have to add an exception for that port.

      .) Start the websocket server example from Qt.

      .) In Google Chrome open: https://123.456.789.10:4433 (your server IP address and port) and continue to add an security excpetion for that address.

      .) Open the client html site twice in your Google Chrome browser.

      .) First Tab:

      Click connect to connect to the websocket server. You should receive a "Connected" message. This means that the basic ssl websocket example from the Qt website is basically working and the following behaviour should be reproducible.

      .) Send a "test" - message

      .) Move quickly to the second Tab and connect to the same websocket server from there, click "State".

      .) You should see the "Connecting"-state, which is okay, because the thread is in sleep-mode for 90 seconds
      After 30s Google Chrome returns a timeout error:

      ERROR: undefined
      DISCONNECTED

      After the thread wakes up ("Wake Up" output in the server console) in my case the websocket server is not responsive anymore, I can't establish a connection with any browser or client, so that I have to restart the entire application.

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            tpochep Timur Pocheptsov
            hanshupe Mike Huber
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes