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

QWebSocketServer memory leak

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P1: Critical
    • 5.8
    • 5.5.1, 5.6.0
    • WebSockets
    • None
    • Ubuntu 16.04 64-bit in VirtualBox or
      Windows 7 64-bit
    • b2d610c0ea229e40910fc9aa1bc784d853cfeba8

    Description

      Applications with QWebSocketServer (both with secure / unsecure mode) keep consuming more and more memory with new connections made. Closing and deleting the socket returned by QWebSocketServer::nextPendingConnection() does not release all the allocated memory.

      This can be observed even with the Qt's demos like echoserver and sslechoserver.

      Testing environment:

      • Custom QWebSocketServer-based server or echoserver or sslechoserver
      • A client establishing the connection, sending two short text messages and disconnecting
      • The client does this 5x per second (that high frequency is actually not needed to observe the problem, this is just to demonstrate quickly the memory consumption)
      • There is always zero or one connection at time

      After few minutes the process's private memory consumption grows from ~ 1 - 1.5 MB to megabytes. I did even let it go over 100 MB. I measured the memory consumption using systemmonitor on Ubuntu and Windows Task Manager on Windows.

      I did also run Qt's memcheck (valgrind). It does not report anything in the default settings (at least in the demos), but enabling Show reachable and indirectly lost blocks and External Errors option causes a lot of issues to appear. Example of the most significant issue from one run of echoserver demo for ~15 minutes follows:

      6,176,800 bytes in 15,442 blocks are still reachable in loss record 978 of 978
        in main in /home/osboxes/Qt/Examples/Qt-5.6/qtwebsockets/websockets/echoserver/main.cpp:60
        1: operator new(unsigned long) in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so
        2: QTcpSocket::QTcpSocket(QObject*) in /home/osboxes/Qt/5.6/gcc_64/lib/libQt5Network.so.5.6.0
        3: QTcpServer::incomingConnection(long long) in /home/osboxes/Qt/5.6/gcc_64/lib/libQt5Network.so.5.6.0
        4: /home/osboxes/Qt/5.6/gcc_64/lib/libQt5Network.so.5.6.0
        5: /home/osboxes/Qt/5.6/gcc_64/lib/libQt5Network.so.5.6.0
        6: QCoreApplication::notifyInternal2(QObject*, QEvent*) in /home/osboxes/Qt/5.6/gcc_64/lib/libQt5Core.so.5.6.0
        7: /home/osboxes/Qt/5.6/gcc_64/lib/libQt5Core.so.5.6.0
        8: g_main_context_dispatch in /lib/x86_64-linux-gnu/libglib-2.0.so.0.4800.0
        9: /lib/x86_64-linux-gnu/libglib-2.0.so.0.4800.0
        10: g_main_context_iteration in /lib/x86_64-linux-gnu/libglib-2.0.so.0.4800.0
        11: QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) in /home/osboxes/Qt/5.6/gcc_64/lib/libQt5Core.so.5.6.0
        12: QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) in /home/osboxes/Qt/5.6/gcc_64/lib/libQt5Core.so.5.6.0
        13: QCoreApplication::exec() in /home/osboxes/Qt/5.6/gcc_64/lib/libQt5Core.so.5.6.0
        14: main in /home/osboxes/Qt/Examples/Qt-5.6/qtwebsockets/websockets/echoserver/main.cpp:60
      

      The total number of leaked bytes (still reachable) depends on how long the server runs (how many connections were made).

      Attachments

        Issue Links

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

          Activity

            People

              tpochep Timur Pocheptsov
              lukas.zavitkovsky Lukáš Závitkovský
              Votes:
              5 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes