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

QNetworkDiskCache returns invalid data with a set cache size

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Reported
    • Priority: P2: Important
    • Resolution: Unresolved
    • Affects Version/s: 5.3.1, 5.3.2
    • Fix Version/s: None
    • Component/s: Network: Cache
    • Labels:
      None
    • Environment:
      Archlinux

      Description

      When using a QNetworkDiskCache with setMaximumCacheSize called, and then doing a request with a QNetworkAccessManager twice, the second time (cached) I don't get the data I'd expect but corrupt data instead.

      Looking at wireshark, this is what happens:

      • Qt sends a request, in my case to http://winhelp2002.mvps.org/hosts.txt
      • The server returns the content
      • Qt sends the second request, with an "If-Modified-Since" header.
      • The server sends "304 not modified" back.
      • Qt reads the content from the cache, but if I call readAll on the QNetworkReply, I always get the hex bytes 00 00 00 04 00 00 00 00 instead of the few kilobytes of data I'd expect.

      Attached are two examples: A minimal PyQt5/Python3 example, and the Qt HTTP example with a cache hacked in. With the latter, the bug can be seen by downloading http://winhelp2002.mvps.org/hosts.txt twice, and then looking at the downloaded file.

      (Note: For the C++ example, the cache is hardcoded in /tmp/qtbug-cache and doesn't get deleted automatically - this is the first time I'm doing something in C++, and I don't want to mess with deleting stuff until I feel like I know what I'm doing)

      What I observed so far:

      • It doesn't happen on Windows 8
      • It doesn't happen when the cache size is over a certain limit. For me, it happens with a cache size of 561 kilobytes, and goes away with 562 kilobytes.
      • It doesn't happen when calling setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::AlwaysNetwork) on the request.

      Open questions:

      • Why doesn't this seem to affect QtWebKit?
      • Is there a suitable workaround except disabling the cache for all manual requests?

        Attachments

        1. http.tar.gz
          7 kB
        2. reply_test.py
          1 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

            • Assignee:
              peter-har Peter Hartmann
              Reporter:
              the compiler Florian Bruhin
            • Votes:
              1 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:

                Gerrit Reviews

                There are no open Gerrit changes