Details
-
Bug
-
Resolution: Done
-
P2: Important
-
5.15.9, 6.3.0
-
Debian 11 Bullseye amd64
bluez 5.55-3.1
-
-
5
-
3aafe9d5ce (qt/qtconnectivity/dev) 584b7693bb (qt/qtconnectivity/6.3) 584b7693bb (qt/tqtc-qtconnectivity/6.3) 3aafe9d5ce (qt/tqtc-qtconnectivity/dev) 336bd4ff9e (qt/tqtc-qtconnectivity/5.15) 584b7693bb (qt/qtconnectivity/6.3.1)
-
Team A Foundation Sprint 57, Team A Foundation Sprint 58
Description
It's enough to simply create instance of QBluetoothServer with QBluetoothServiceInfo::L2capProtocol or QBluetoothServiceInfo::RfcommProtocol (and call it's destructor) to reproduce socket leaks. Once application reaches open file limit it hangs/crashes.
It can be reproduced with simple loop (full project with CMakeLists attached):
#include <QBluetoothServer> #include <QByteArray> #include <QCoreApplication> #include <QDebug> #include <QProcess> #include <QString> QByteArray runInBash(const QString &command) { QProcess process; process.start(QStringLiteral("/usr/bin/bash"), {QStringLiteral("-c"), command}); process.waitForFinished(); return process.readAllStandardOutput(); } int getRFCommSocketCount() { const auto output{runInBash(QStringLiteral("lsof -p %1 | grep RFCOMM | wc -l").arg(qApp->applicationPid()))}; //qDebug() << output; return output.toInt(); } int getL2CapSocketCount() { const auto output{runInBash(QStringLiteral("lsof -p %1 | grep L2CAP | wc -l").arg(qApp->applicationPid()))}; //qDebug() << output; return output.toInt(); } int main(int argc, char *argv[]) { QCoreApplication a{argc, argv}; while (true) { { QBluetoothServer server{QBluetoothServiceInfo::L2capProtocol}; qDebug() << "Current L2CAP socket count:" << getL2CapSocketCount(); } { QBluetoothServer server{QBluetoothServiceInfo::RfcommProtocol}; qDebug() << "Current RFCOMM socket count:" << getRFCommSocketCount(); } } return 0; }
In Qt 5.15.9 case, application hangs after reaching limit:
Current L2CAP socket count: 504 Current RFCOMM socket count: 504 Current L2CAP socket count: 505 Current RFCOMM socket count: 505
In Qt 6.3.0 application keeps running, probably because QProcess error handling works better:
Current L2CAP socket count: 504 Current RFCOMM socket count: 504 Current L2CAP socket count: 505 Current RFCOMM socket count: 505 Current L2CAP socket count: 0 QProcessPrivate::createPipe: Cannot create pipe 0x560a7ece6710 (Too many open files) Current RFCOMM socket count: 0 QProcessPrivate::createPipe: Cannot create pipe 0x560a7ece6710 (Too many open files) Current L2CAP socket count: 0
Attachments
For Gerrit Dashboard: QTBUG-103067 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
411198,3 | Close socket descriptor when QBluetoothSocketBluez is destroyed | dev | qt/qtconnectivity | Status: MERGED | +2 | 0 |
413344,2 | Close socket descriptor when QBluetoothSocketBluez is destroyed | 6.3 | qt/qtconnectivity | Status: MERGED | +2 | 0 |
413345,2 | Close socket descriptor when QBluetoothSocketBluez is destroyed | tqtc/lts-6.2 | qt/tqtc-qtconnectivity | Status: MERGED | +2 | 0 |
413346,4 | Close socket descriptor when QBluetoothSocketBluez is destroyed | tqtc/lts-5.15 | qt/tqtc-qtconnectivity | Status: MERGED | +2 | 0 |