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

QWebEngineProfile::clearHttpCache() can subsequently cause QWebEnginePage::load() to hang

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P2: Important
    • 6.7.0 FF
    • 5.15.12, 6.2.7, 6.4.2, 6.5.0 Beta2
    • WebEngine
    • Windows 10 22H2 Pro, MSVC 2019 x64
    • Linux/X11, Windows
    • 889567af4 (112-based), 37430020d (dev)

    Description

      Code

      sample.html

      <html><body>
          <img src="https://www.qt.io/hubfs/2016_Qt_Logo/qt_logo_green_rgb_16x16.png" />
      </body></html>
      

      main.cpp

      int main(int argc, char* argv[])
      {
          QApplication app(argc, argv);
      
          QUrl sampleUrl("qrc:/sample.html");
      
          QWebEnginePage page;
          page.settings()->setAttribute(QWebEngineSettings::LocalContentCanAccessRemoteUrls, true);
      
          QObject::connect(&page, &QWebEnginePage::loadProgress, [](int progress)
          {
              qDebug() << "Loading progress:" << progress;
          });
          QObject::connect(&page, &QWebEnginePage::loadFinished, [&]
          {
              qDebug("Finished!");
      
              static bool firstReload = true;
              if (!firstReload)
              {
                  qDebug("Quitting");
                  qApp->quit();
                  return;
              }
      
              qDebug("Clearing cache");
              page.profile()->clearHttpCache();
      
              firstReload = false;
      
              // WORKAROUND: Wrap the lines below around a QTimer::singleShot()
              //             with a sufficiently large delay (say, 100ms - 500ms)
              qDebug("Reloading...");
              page.load(sampleUrl);
          });
          page.load(sampleUrl);
      
          return app.exec();
      }
      

       

      Expected output

      Loading progress: 0
      Loading progress: 70
      Loading progress: 80
      Loading progress: 100
      Finished!
      Clearing cache
      Reloading...
      Loading progress: 0
      Loading progress: 70
      Loading progress: 100
      Finished!
      Quitting
      

       

      Actual output

      Loading progress: 0
      Loading progress: 70
      Loading progress: 80
      Loading progress: 100
      Finished!
      Clearing cache
      Reloading...
      Loading progress: 0
      Loading progress: 80
      

      The 2nd load never finishes so the app never quits.

       

      Notes

      • This seems to be some kind of race condition:
        • On one Windows 10 PC, I can reproduce this 100% of the time on Qt 6.x, but never on Qt 5.15
        • On another Windows 10 PC, I can only reproduce this ~50% of the time on all versions of Qt
      • Setting QWebEngineProfile::NoCache seems to have no effect

       

      Workaround?

      If we introduce a delay between calling QWebEngineProfile::clearHttpCache() and QWebEnginePage::load(), it seems to work fine.

      On my PC, 10ms was still too small while 500ms seemed to be enough that it never hangs.

      Attachments

        Issue Links

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

          Activity

            People

              pvarga Peter Varga
              skoh-qt Sze Howe Koh
              Votes:
              1 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes