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

[WASM] QWebSocket does not emit QWebSocket::binaryFrameReceived(), can freeze GUI

    XMLWordPrintable

Details

    • Bug
    • Resolution: Out of scope
    • P2: Important
    • None
    • 6.7.0
    • WebSockets
    • Windows 10 22H2
    • WebAssembly

    Description

      Code

      // Server
      int main(int argc, char *argv[])
      {
          QCoreApplication app(argc, argv);
      
          const int sz_megabytes = 200;
          const int sz_bytes = sz_megabytes * 1024 * 1024;
          const int listSize = sz_bytes / sizeof(quint64);
      
          QList<quint64> numbers;
          numbers.reserve(listSize);
          for (quint64 i = 0; i < listSize; ++i)
              numbers << i;
      
          const QByteArray bytes(reinterpret_cast<const char*>(numbers.constData()), sz_bytes);
      
          QWebSocketServer server(u"Big Binary Server"_s, QWebSocketServer::NonSecureMode);
          QObject::connect(&server, &QWebSocketServer::newConnection, &app, [&]{
              auto client = server.nextPendingConnection();
              if (!client)
                  return;
      
              qDebug() << "Sending big payload to" << client;
              auto bytesSent = client->sendBinaryMessage(bytes);
              qDebug() << "Sent" << bytesSent << "bytes";
          });
          server.listen(QHostAddress::LocalHost, 54321);
      
          return app.exec();
      }
      
      // Client
      int main(int argc, char *argv[])
      {
          QApplication app(argc, argv);
      
          auto bar = new QProgressBar;
          bar->setMinimum(0);
          bar->setMaximum(100);
          bar->show();
      
          QPropertyAnimation anim(bar, "value");
          anim.setStartValue(0);
          anim.setEndValue(100);
          anim.setDuration(1000);
          anim.setLoopCount(-1);
          anim.start();
      
          auto log = new QPlainTextEdit;
      
          QWidget window;
          auto layout = new QVBoxLayout(&window);
          layout->addWidget(bar);
          layout->addWidget(log);
          window.resize(800, 600);
          window.show();
      
          QWebSocket socket("test.localhost");
          QObject::connect(&socket, &QWebSocket::binaryFrameReceived, &app, [&](const QByteArray &frame, bool isLastFrame){
              log->appendPlainText(u"Received frame, size = %1 Last frame?: "_s.arg(frame.size()) + (isLastFrame ? "Yes" : "No"));
          });
          QObject::connect(&socket, &QWebSocket::binaryMessageReceived, &app, [&](const QByteArray &message){
              log->appendPlainText(u"Received message, size = %1"_s.arg(message.size()));
          });
          QTimer::singleShot(2000, &app, [&]{
              QUrl url("ws://localhost:54321");
              log->appendPlainText(u"Connecting to %1"_s.arg(url.toString()));
              socket.open(url);
          });
      
          return app.exec();
      }
      

       

      Steps to reproduce
      Do all the steps below on the same machine:

      1. Build and run the attached server example on a Desktop kit. Keep the server running until all steps below are complete.
      2. Build and run the attached client example on a Desktop kit. Watch its GUI until you see "Received message".
      3. Build and run the attached client example on a WASM kit. Watch its GUI until you see "Received message".

       

      Expected outcomes (Windows)
      The client reports receiving many frames; the client's GUI animates smoothly throughout the test.

      Connecting to ws://localhost:54321
      Received frame, size = 524288 Last frame?: No
      Received frame, size = 524288 Last frame?: No
      ...
      Received frame, size = 524288 Last frame?: No
      Received frame, size = 524288 Last frame?: No
      Received frame, size = 524288 Last frame?: Yes
      Received message, size = 209715200
      

       

      Actual outcomes (WASM)
      The client does not report receiving any frames; the client's GUI freezes/stutters while processing the data.

      Connecting to ws://localhost:54321
      Received message, size = 209715200
      

      Attachments

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

        Activity

          People

            lpotter Lorn Potter
            skoh-qt Sze Howe Koh
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes