title: Network transferred finished but QNetworkReply read data very slow
body: <p>I am using QNetworkAccessManager to communicate with my RESTful APIserver, one of my API need to fetch a file from server by GET, commonly the file size is about 3MB. Most of time it works very well and very fast, but sometimes it may take very long time and end with <code>RemoteHostClosedError</code>.</p>
  <p>My environment:</p>
  <ul>
  <li>Qt 5.5 MinGW</li>
  <li>Windows 10 64bit</li>
  <li>API server run on the same computer</li>
  </ul>
  <p>Here is my code to send GET request for the file:</p>
  <pre class="lang-cpp prettyprint-override"><code>    QUrl url(QString(&quot;http://%1:%2/audio/channels&quot;)
               .arg(m_ip)
               .arg(m_port));
      QNetworkRequest request(url);
      QNetworkReply *reply = m_http-&gt;get(request);
      // Use lamdba to handle fetched file
      connect(reply, &amp;QNetworkReply::finished, [this, reply]{
          // Handle fetched file
      });
  </code></pre>
  <p>When the slow issue occurred, I did wireshark capture, but I found the network transfer is finished very fast and all data is transferred, here is a snapshot of Wireshark capture: <a href="https://i.stack.imgur.com/RcogS.png" rel="nofollow noreferrer">Wireshark capture</a></p>
  <p>I also add slot to signal QNetworkReply::downloadProgress, then I found QNetworkReply was always trying to download the data, but very slow at about 5KB/s.
  Here is the test code:</p>
  <pre class="lang-cpp prettyprint-override"><code>connect(reply, &amp;QNetworkReply::downloadProgress, [this, reply](qint64 recved, qint64 total){
          qDebug().noquote() &lt;&lt; QDateTime::currentDateTimeUtc()
                             &lt;&lt; &quot; Downloading from &quot; &lt;&lt; m_ip &lt;&lt; &quot;:&quot; &lt;&lt; m_port
                             &lt;&lt; &quot;: &quot; &lt;&lt; recved &lt;&lt; &quot;/&quot; &lt;&lt; total;
      });
  </code></pre>
  <p>Here is part of log output:</p>
  <pre><code>QDateTime(2022-04-20 09:06:32.870 UTC Qt::TimeSpec(UTC))  Downloading from  127.0.0.1 : 8800 :  1144846 / 3070158
  QDateTime(2022-04-20 09:06:32.969 UTC Qt::TimeSpec(UTC))  Downloading from  127.0.0.1 : 8800 :  1145501 / 3070158
  QDateTime(2022-04-20 09:06:33.070 UTC Qt::TimeSpec(UTC))  Downloading from  127.0.0.1 : 8800 :  1146160 / 3070158
  QDateTime(2022-04-20 09:06:33.170 UTC Qt::TimeSpec(UTC))  Downloading from  127.0.0.1 : 8800 :  1146837 / 3070158
  QDateTime(2022-04-20 09:06:33.271 UTC Qt::TimeSpec(UTC))  Downloading from  127.0.0.1 : 8800 :  1147504 / 3070158
  QDateTime(2022-04-20 09:06:33.371 UTC Qt::TimeSpec(UTC))  Downloading from  127.0.0.1 : 8800 :  1148132 / 3070158
  QDateTime(2022-04-20 09:06:33.470 UTC Qt::TimeSpec(UTC))  Downloading from  127.0.0.1 : 8800 :  1148751 / 3070158
  QDateTime(2022-04-20 09:06:33.571 UTC Qt::TimeSpec(UTC))  Downloading from  127.0.0.1 : 8800 :  1149403 / 3070158
  QDateTime(2022-04-20 09:06:33.671 UTC Qt::TimeSpec(UTC))  Downloading from  127.0.0.1 : 8800 :  1150056 / 3070158
  QDateTime(2022-04-20 09:06:33.771 UTC Qt::TimeSpec(UTC))  Downloading from  127.0.0.1 : 8800 :  1150729 / 3070158
  QDateTime(2022-04-20 09:06:33.871 UTC Qt::TimeSpec(UTC))  Downloading from  127.0.0.1 : 8800 :  1151360 / 3070158
  QDateTime(2022-04-20 09:06:33.971 UTC Qt::TimeSpec(UTC))  Downloading from  127.0.0.1 : 8800 :  1152040 / 3070158
  QDateTime(2022-04-20 09:06:34.071 UTC Qt::TimeSpec(UTC))  Downloading from  127.0.0.1 : 8800 :  1152707 / 3070158
  QDateTime(2022-04-20 09:06:34.171 UTC Qt::TimeSpec(UTC))  Downloading from  127.0.0.1 : 8800 :  1153354 / 3070158
  QDateTime(2022-04-20 09:06:34.272 UTC Qt::TimeSpec(UTC))  Downloading from  127.0.0.1 : 8800 :  1153973 / 3070158
  QDateTime(2022-04-20 09:06:34.371 UTC Qt::TimeSpec(UTC))  Downloading from  127.0.0.1 : 8800 :  1154618 / 3070158
  QDateTime(2022-04-20 09:06:34.471 UTC Qt::TimeSpec(UTC))  Downloading from  127.0.0.1 : 8800 :  1155259 / 3070158
  QDateTime(2022-04-20 09:06:34.572 UTC Qt::TimeSpec(UTC))  Downloading from  127.0.0.1 : 8800 :  1155936 / 3070158
  QDateTime(2022-04-20 09:06:34.673 UTC Qt::TimeSpec(UTC))  Downloading from  127.0.0.1 : 8800 :  1156592 / 3070158
  QDateTime(2022-04-20 09:06:34.772 UTC Qt::TimeSpec(UTC))  Downloading from  127.0.0.1 : 8800 :  1157242 / 3070158
  QDateTime(2022-04-20 09:06:34.873 UTC Qt::TimeSpec(UTC))  Downloading from  127.0.0.1 : 8800 :  1157808 / 3070158
  QDateTime(2022-04-20 09:06:34.973 UTC Qt::TimeSpec(UTC))  Downloading from  127.0.0.1 : 8800 :  1158460 / 3070158
  QDateTime(2022-04-20 09:06:35.073 UTC Qt::TimeSpec(UTC))  Downloading from  127.0.0.1 : 8800 :  1159104 / 3070158
  QDateTime(2022-04-20 09:06:35.173 UTC Qt::TimeSpec(UTC))  Downloading from  127.0.0.1 : 8800 :  1159735 / 3070158
  QDateTime(2022-04-20 09:06:35.273 UTC Qt::TimeSpec(UTC))  Downloading from  127.0.0.1 : 8800 :  1160407 / 3070158
  QDateTime(2022-04-20 09:06:35.373 UTC Qt::TimeSpec(UTC))  Downloading from  127.0.0.1 : 8800 :  1161049 / 3070158
  QDateTime(2022-04-20 09:06:35.474 UTC Qt::TimeSpec(UTC))  Downloading from  127.0.0.1 : 8800 :  1161669 / 3070158
  QDateTime(2022-04-20 09:06:35.573 UTC Qt::TimeSpec(UTC))  Downloading from  127.0.0.1 : 8800 :  1162266 / 3070158
  QDateTime(2022-04-20 09:06:35.673 UTC Qt::TimeSpec(UTC))  Downloading from  127.0.0.1 : 8800 :  1162852 / 3070158
  QDateTime(2022-04-20 09:06:35.682 UTC Qt::TimeSpec(UTC))  Downloading from  127.0.0.1 : 8800 :  1162901 / 3070158
  </code></pre>
  <p>Based on my tests, I think it is the reason of QNetworkReply data reading process, it is too slow,  but the actual network transferred is finished very fast, after about 3 minutes, server close the connection, then QNetworkReply get the error <code>RemoteHostClosedError</code>, finally cause failed request.</p>
  <p>I am confused why network transferred finished, which means the data is already downloaded, but QNetworkReply still take so long to process these data.</p>
  <p>Really appreciate if anyone can help me with this, Thanks.</p>