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

In given conditions, QNetworkAccessManager will disconnect before QNetworkReply read response data

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 5.12.1
    • Network: HTTP
    • None
    • windows7 x86_64
      msys2 mingw-w64-i686-qt5-static- 5.12.1
    • Windows

    Description

      Conditions:

      1. QNetworkRequest setRawHeader("Connection", "close")

      2. QNetworkAccessManager post

      Example:

      // golang http server
      package main
       
      import (
          "net/http"
      )
       
      func IndexHandler(w http.ResponseWriter, r *http.Request) {
          w.Write([]byte("<html><body>test</body></html>"))
      }
       
      func main() {
          http.HandleFunc("/test", IndexHandler)
          http.ListenAndServe("127.0.0.1:8080", nil) 
      }
      
        // qt
              QByteArray payload;
              payload.append("test");
              auto url = QUrl{"http://127.0.0.1:8080/test"};
              QNetworkRequest req(url);
              req.setRawHeader("Content-Type", "application/octet-stream");
              req.setRawHeader("Connection", "keep-alive");
              QNetworkAccessManager http;
              auto reply = http.post(req, payload);
      
              QTimer timer;
              timer.setInterval(30000);
              timer.setSingleShot(true);
      
              QEventLoop loop;
              connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
              connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
              timer.start();
              loop.exec();
      
              timer.stop();
              if (reply->isRunning())
              {
                  qDebug("timeout");
                  reply->abort();
                  delete reply;
                  return;
              }
      
              auto err = reply->error();//RemoteHostClosedError mostly
              auto html = reply->readAll();
              delete reply;
      

      Most of the time you will get RemoteHostClosedError

      if replace

      req.setRawHeader("Connection", "close")

      with

      req.setRawHeader("Connection", "keep-alive")

      then everything goes well.
       

      curl -X POST -v -H "Connection: close" -H "Content-Type: application/octet-stream" --data-binary test http://127.0.0.1:8080/test
      // everything's fine with curl every time
      // if it's http server's problem, then why curl working just fine every time ?

      Obviously, QNetworkAccessManager disconnect before QNetworkReply could fetch response data.

      Attachments

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

        Activity

          People

            cnn Qt Core & Network
            alexzhang Alex Zhang
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes