Details
-
Bug
-
Resolution: Unresolved
-
P3: Somewhat important
-
None
-
5.15.6
-
None
-
Operating System: Kubuntu 23.04
KDE Plasma Version: 5.27.4
KDE Frameworks Version: 5.104.0
Qt Version: 5.15.8
Kernel Version: 6.2.0-27-generic (64-bit)
Graphics Platform: X11
Processors: 4 × Intel® Core™ i7-3520M CPU @ 2.90GHz
Memory: 15.5 GiB of RAM
Graphics Processor: Mesa Intel® HD Graphics 4000
Manufacturer: LENOVO
Product Name: Lenovo G780
System Version: Lenovo G780Operating System: Kubuntu 23.04 KDE Plasma Version: 5.27.4 KDE Frameworks Version: 5.104.0 Qt Version: 5.15.8 Kernel Version: 6.2.0-27-generic (64-bit) Graphics Platform: X11 Processors: 4 × Intel® Core™ i7-3520M CPU @ 2.90GHz Memory: 15.5 GiB of RAM Graphics Processor: Mesa Intel® HD Graphics 4000 Manufacturer: LENOVO Product Name: Lenovo G780 System Version: Lenovo G780
Description
I'm using several QNetworkAccessManager in the app. A single QNetworkAccessManager instance per thread. Threads are spawned and destroyed per request. So QNetworkAccessManager too.
It was noticed that accessing some URLs cause open socket (states ESTABLISHED, then CLOSE_WAIT) left in system. After a while the app reaches limit of open file descriptors and crash with `GLib-ERROR **: Creating pipes for GWakeup: Too many open files`. The leaked sockets could be seen in terminal while the app is running by command `sudo lsof -c myapp`.
Only specific URLs cause that problem. These are FTP urls. 2 of 3 ftp URLs I tested cause the problem. I guess that related to "active/passive" ftp server mode.
I sugest this URL to reproduce the problem: `ftp://ftp.kiam1.rssi.ru/pub/gps/solar/solarinex.txt`
The code to reproduce is following:
#test.h
```
#ifndef TEST_H
#define TEST_H
#include <QObject>
#include <QThread>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QDebug>
class QMyThread: public QThread
{
Q_OBJECT
public:
explicit QMyThread(QObject* parent = nullptr): QThread(parent) {}
~QMyThread(){qDebug() << "thread destroy";}
void run() override
{
qDebug() << "thread start";
QNetworkRequest request(QUrl("ftp://ftp.kiam1.rssi.ru/pub/gps/solar/solarinex.txt"));
QNetworkAccessManager nam;
nam.setTransferTimeout();
QNetworkReply *response = nam.get(request);
connect(response, &QNetworkReply::errorOccurred, this, [=](QNetworkReply::NetworkError err)
{ qDebug() << QString("error %1").arg(err); });
connect(response, &QNetworkReply::redirected, this, [=](const QUrl &url)
{ qDebug() << QString("redir %1").arg(url.toString()); });
connect(response, &QNetworkReply::finished, this, [=]() {
if (response->error() != QNetworkReply::NoError)
else
{ response->readAll(); } quit();
});
exec();
if (response)
{ qDebug() << "response deleted"; response->deleteLater(); } qDebug() << "thread stop";
}
};
#endif // TEST_H
```
#main.cpp
```
#include <QCoreApplication>
#include "test.h"
int main(int argc, char *argv[])
{ QCoreApplication a(argc, argv); QMyThread* thread = new QMyThread; QObject::connect(thread, &QThread::finished, thread, &QObject::deleteLater); thread->start(); return a.exec(); }```
#app output:
```
thread start
response deleted
thread stop
thread destroy
```
app open sockets left after "thread destroy":
` sudo lsof -c untitled`
Expected behaviour:
No any open TCP sockets to ftp addresses after QNetworkAccessManager is destroyed.