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
This commit is contained in:
Basile Clement 2025-04-12 05:01:35 +02:00 committed by GitHub
parent 9463390e80
commit b214933da9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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);
}