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

Several issues when aborting network request

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P2: Important P2: Important
    • 6.6, 6.7.1, 6.8.0 FF
    • 6.5.3
    • Network: HTTP
    • None
    • be6644c1f (dev), 518ce19c7 (6.7), a64d1021d (6.6)

      This is actualised version of the QTBUG-36127, which is pretty old and seems forgotten.

      See sample code:

      #include <QtCore/QCoreApplication>
      #include <QtCore/QEventLoop>
      #include <QtCore/QTimer>
      #include <QtNetwork/QNetworkAccessManager>
      #include <QtNetwork/QNetworkReply>
      
      int main(int argc, char** argv)
      {
          int finishCount = 0;
      
          QCoreApplication app(argc, argv);
      
          QNetworkAccessManager network;
          QNetworkReply* reply = network.post(QNetworkRequest(QUrl("http://invalid-hostname")), QByteArray("foo bar"));
      
          QObject::connect(reply, &QNetworkReply::finished, reply, [&] { ++finishCount; });
      
          reply->abort();
          QEventLoop eventLoop;
          QTimer::singleShot(200, &eventLoop, &QEventLoop::quit);
          eventLoop.exec();
      
          reply->deleteLater();
      
          qWarning() << "Finish count" << finishCount;
      
          return 0;
      };
      

      When aborting network request, e.g. by timeout, we can encounter several issues:
      1. Internal Qt warning: "QNetworkReplyImplPrivate::error: Internal problem, this method must only be called once."
      2. finished() signal and corresponding slot might be called twice.

      With the code sample above both problems are stably reproduced for me at least on macOS.

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

            manordheim MÃ¥rten Nordheim
            studiosus Vladimir Belyavsky
            Votes:
            1 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes