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

WinRT QUdpSocket pendingDatagram list is unsafely used by multiple threads

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P1: Critical
    • 5.8.0 RC
    • 5.6.0, 5.7.0 Beta
    • Network: Sockets
    • None
    • WinRT
    • WinRT
    • fc35f9496439d7a236f7be1eecae53ad6ddd9112

    Description

      QNativeSocketEnginePrivate pendingDatagram QList member is appended and popped from by two different threads leading to eventual crash when used with fast UDP senders.

      A foreign thread appends in QNativeSocketEnginePrivate::handleNewDatagram.

      And the socket owner thread pop QNativeSocketEngine::readDatagram.

      Minimal example (can be in the same app instance)
          // receiver
          auto receiver = new QUdpSocket(&app);
          if (!receiver->bind()) {
              qFatal("bind() failed");
          }
          auto localPort = receiver->localPort();
          QObject::connect(receiver,&QUdpSocket::readyRead, receiver, [receiver]() {
              QByteArray data(receiver->pendingDatagramSize(), Qt::Uninitialized);
              receiver->readDatagram(data.data(), data.size());
          });
      
          // sender
          auto sender = new QUdpSocket(&app);
          auto timer = new QTimer(&app);
          timer->setInterval(0);
          timer->setSingleShot(false);
          QObject::connect(timer, &QTimer::timeout, sender, [sender,localPort]() {
              sender->writeDatagram({},QHostAddress::LocalHost, localPort);
          });
          timer->start();
      

      Will typically crash in 2-10 seconds somewhere in QList. Doing burst of writeDatagram or running the app in two instances will probably speed it up, but isn't required.

      Attachments

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

        Activity

          People

            owolff Oliver Wolff
            kristjanbb Kristján Birgisson
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes