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

QNetworkAccessManager blocks its thread (freezes) when server unreachable



    • Type: Bug
    • Status: Closed
    • Priority: P3: Somewhat important
    • Resolution: Invalid
    • Affects Version/s: 5.9.0 Beta 3
    • Fix Version/s: None
    • Labels:
    • Environment:
      Windows 7 64-bit, msvc2015 compilation of 5.9beta3 openssl 1.0.2h


      When server is unreachable, post() from QNetworkAccessManager(NAM) blocks thread's eventloop, it practically freezes the thread, even if the timout signal is triggered, the quit slot is not called, it is just appended to the queue (it is been debugged while using) and is called after NAM stoppes blocking it, which can be minute or two. SSL is checked and everything is correct, even the version of openssl library. If I use dynamically created NAM or timer, the behaviour is the same. Unknown error is printed no slot is triggered from reply signals. No Ssl error or the other. The problem is that the thread is not responsive to user inputs either like quiting the application which has to wait until the NAM stops blocking the eventloop. Quit slot of the thread of course tries to interrupt the eventLoopServer in the presented method, but the slot is called after the NAM stops blocking the thread's eventloop.

      added based on comments
      In main I create MyApplication in which constructor I create my own class LicenseController, when the thread starts the init procedure is called so the local event loop I use to wait for server response is created in given thread. The thread LicenseController lives in is not accessing any other slot while the NAM does not return finished, its blocking given thread for unknown reason. After NAM emits finished the quit slot is called. Quit is not even called by the setuped timer. It would be usefull to have built in timer in NAM, for such cases. Otherwise when user tries to cancel the eventloop by itself, it does not let him, but it waits one or two minutes.

       QNetworkAccessManager mgr;
      QObject::connect(&mgr, SIGNAL(finished(QNetworkReply*)), eventLoopServer, SLOT(quit()));
      //eventLoopServer is created in init procedure, which is called after the thread of this controller class has been started
      QTimer timer;
      QObject::connect(&timer, SIGNAL(timeout()), eventLoopServer, SLOT(quit()));

      QNetworkRequest request( QUrl( QString("my url address") ) );//there is valid url (checked), not possible to share

      QUrlQuery params;
      QByteArray postData ;

      QString headerData = "secret header";//changed to be able to publish
      request.setRawHeader("Authorization", headerData.toLocal8Bit());
      request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");

      QSslConfiguration conf = request.sslConfiguration();

      QNetworkReply *reply=mgr.post(request, postData);
      QObject::connect(reply, SIGNAL(sslErrors(QList<QSslError>)), this, SLOT(processSSLError(QList<QSslError>)));
      QObject::connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(processError(QNetworkReply::NetworkError)));
      QObject::connect(reply, SIGNAL(finished()),eventLoopServer, SLOT(quit()));

      QString strReply = (QString)reply->readAll();
      qDebug()<<reply->errorString(); // prints "Unknown error"


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



            tpochep Timur Pocheptsov
            fogelton fogelton
            0 Vote for this issue
            3 Start watching this issue



                Gerrit Reviews

                There are no open Gerrit changes