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

QBluetoothServer leaks RFCOMM and L2CAP Linux sockets

    XMLWordPrintable

Details

    • Linux/X11
    • 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

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

        Activity

          People

            vuokko Juha Vuolle
            vdargis_at_uab_styritrade Vincas Dargis
            Vladimir Minenko Vladimir Minenko
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews