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

ssl websocketserver stops accepting new connections

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P1: Critical
    • 5.14
    • 5.6.2, 5.7.0, 5.8.0 Beta
    • WebSockets
    • None
    • 2e54dbe86eac61e87782a138dbcc158cb6b10cd9

    Description

      Many connection attempts to a SSL-Websocketserver with a non-SSL Websocket causes the Websocketserver to accept any new connections.

      I already looked into the server code. The reason for this behaviour is caused by this section:

      websockets/sslserver.cpp
      [...]
      void QSslServer::incomingConnection(qintptr socket)
      {
          QSslSocket *pSslSocket = new QSslSocket();
      
          if (Q_LIKELY(pSslSocket)) {
              pSslSocket->setSslConfiguration(m_sslConfiguration);
      
              if (Q_LIKELY(pSslSocket->setSocketDescriptor(socket))) {
                  connect(pSslSocket, &QSslSocket::peerVerifyError, this, &QSslServer::peerVerifyError);
      
                  typedef void (QSslSocket::* sslErrorsSignal)(const QList<QSslError> &);
                  connect(pSslSocket, static_cast<sslErrorsSignal>(&QSslSocket::sslErrors),
                          this, &QSslServer::sslErrors);
                  connect(pSslSocket, &QSslSocket::encrypted, this, &QSslServer::newEncryptedConnection);
                  connect(pSslSocket, &QSslSocket::preSharedKeyAuthenticationRequired, this, &QSslServer::preSharedKeyAuthenticationRequired);
      
                  addPendingConnection(pSslSocket);
      
                  pSslSocket->startServerEncryption();
              } else {
                 delete pSslSocket;
              }
          }
      }
      [...]
      

      The new socket is appended to the queue with addPendingConnection. But the signal QSslSocket::encrypted is never emitted, so the connection never gets dequeued with nextPendingConnection in QWebSocketServerPrivate::onNewConnection. As a result, QTcpServer stops accepting new connections when maxPendingConnections is reached.

      This can be reproduced with SSL Echo Client Example. I've modifed the code accordingly:

      sslechoclient/main.cpp
      // Tested with SslEchClient changed
      // void SslEchoClient::onTextMessageReceived(QString message)
      // {
      //     qDebug() << "Message received:" << message;
      //     //qApp->quit(); -- disabled
      // }
      
      int main(int argc, char *argv[])
      {
          QCoreApplication a(argc, argv);
      
          new SslEchoClient(QUrl(QStringLiteral("wss://localhost:1234")));
      
          for (int i = 0; i < 40; i++)
              new SslEchoClient(QUrl(QStringLiteral("ws://localhost:1234")));
      
          QTimer::singleShot(2500, [&] {
              a.quit();
          });
      
          return a.exec();
      }
      

      Attachments

        Issue Links

          For Gerrit Dashboard: QTBUG-57026
          # Subject Branch Project Status CR V

          Activity

            People

              hvoigt Heiko Voigt
              hfx Hubert Feurstein
              Votes:
              5 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There is 1 open Gerrit change