From b214933da9c672c8e100bee8c4b53c3e7129b056 Mon Sep 17 00:00:00 2001 From: Basile Clement Date: Sat, 12 Apr 2025 05:01:35 +0200 Subject: [PATCH] fix: Disable HTTP compression when downloading pictures (#5793) This causes Qt to leak file descriptors and causes the "Too many open file descriptors" error that we sporadically see, see https://bugreports.qt.io/browse/QTBUG-135641 --- .../ui/picture_loader/picture_loader_worker.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/cockatrice/src/client/ui/picture_loader/picture_loader_worker.cpp b/cockatrice/src/client/ui/picture_loader/picture_loader_worker.cpp index a1cfa53be..89559983c 100644 --- a/cockatrice/src/client/ui/picture_loader/picture_loader_worker.cpp +++ b/cockatrice/src/client/ui/picture_loader/picture_loader_worker.cpp @@ -244,6 +244,23 @@ QNetworkReply *PictureLoaderWorker::makeRequest(const QUrl &url) QNetworkRequest req(url); + // QNetworkDiskCache leaks file descriptors when downloading compressed + // files, see https://bugreports.qt.io/browse/QTBUG-135641 + // + // We can set the Accept-Encoding header manually to disable Qt's automatic + // response decompression, but then we would have to deal with decompression + // ourselves. + // + // Since we are dowloading images that are usually stored in a + // compressed format (e.g. jpeg or webp), it's not clear compression at the + // HTTP level helps; in fact, images are typically returned without + // compression. Redirects, on the other hand, are compressed and cause file + // descriptor leaks -- but since redirects have no payload, we don't really + // care either. + // + // In the end, just do the simple thing and disable HTTP compression. + req.setRawHeader("accept-encoding", "identity"); + if (!picDownload) { req.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::AlwaysCache); }