App crash calling QTcpSocket::waitForConnected

  • Hi, I have the following error:
    the next function is called multiple times from diferent threads and after some time, say 20 minutes, crash in socket->waitForConnected(1000). Anybody? Thanks.

    bool Utils::testConnectionToServer(QString host, int port)
        QTcpSocket * socket = new QTcpSocket();
        socket->connectToHost(host, port, QIODevice::ReadOnly);
        if (socket->waitForConnected(1000)) {
            delete socket;
            socket = 0;
            return true;
        } else {
            qDebug() << "### " << socket->errorString() << " ###";
            delete socket;
            socket = 0;
            return false;

  • Qt Champions 2016

    Hi and welcome
    Have you checked that new can allocate always ?
    You might fragment memory if calls happens really fast.

    Also , any chance that the threads call it at the SAME time ?
    so following situation could arise ? (when times perfectly)
    QTcpSocket * socket = new QTcpSocket(); << Thread 1 here
    socket->connectToHost(host, port, QIODevice::ReadOnly) ; << Thread 2 here

  • Previously he had a version of the function that used QMutexLocker to avoid just that but also crash in waitForConnected. Specifically, the error displayed is as follows:

    *** buffer overflow detected ***: /home/kiyov/RepoSVN/tss-streamingserver/trunk/StreamingServer/StreamingServer/Server terminated
    ======= Backtrace: =========

  • Qt Champions 2016

    it looks like buffer overrun happens inside Qt.
    Have you searched the bug database for issues sounding like this`?

  • @mrjj no, where I can search that bug?

  • Qt Champions 2016

  • @mrjj Thanks

  • Qt Champions 2016

    Hope you find something.

    Is it always after the same amount of calls?

  • @mrjj I do not know, I have done this test.

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    I'd change the delete statement by socket->deleteLater() to ensure that you are not deleting the sockets while there's still an event going on the socket.

  • @mrjj No, but it made approximately 1348 calls.

    @SGaist Even changing the delete statement by socket->deleteLeter() the problem persist.

    Apparently all starts in the call to QNativeSocketEnginePrivate::nativeSelect.

    This is the stack trace
    0 __GI_raise raise.c 56 0x7ffff48fd107
    1 __GI_abort abort.c 89 0x7ffff48fe4e8
    2 __libc_message libc_fatal.c 175 0x7ffff493b204
    3 __GI___fortify_fail fortify_fail.c 31 0x7ffff49be4c7
    4 __GI___chk_fail chk_fail.c 28 0x7ffff49bc6e0
    5 __fdelt_chk fdelt_chk.c 25 0x7ffff49be437
    6 QNativeSocketEnginePrivate::nativeSelect qnativesocketengine_unix.cpp 1073 0x7ffff5968e25
    7 QNativeSocketEngine::waitForWrite qnativesocketengine.cpp 947 0x7ffff5966a8d
    8 QAbstractSocket::waitForConnected qabstractsocket.cpp 1814 0x7ffff595f27a
    9 Utils::testConnectionToServer Utils.cpp 106 0x43a099
    10 MyAmqpClient::publishMessage myamqpclient.cpp 206 0x4361d2
    11 Utils::sendMessageToAmqp Utils.cpp 73 0x439bae
    12 StreamingServer::checkSystemResources streamingserver.cpp 1083 0x4152bb
    13 StreamingServer::qt_static_metacall moc_streamingserver.cpp 107 0x459099
    14 QObject::event qobject.cpp 1222 0x7ffff5544e11
    15 QCoreApplication::notifyInternal qcoreapplication.cpp 955 0x7ffff552b71d
    16 sendEvent qcoreapplication.h 231 0x7ffff552efc1
    17 QCoreApplicationPrivate::sendPostedEvents qcoreapplication.cpp 1579 0x7ffff552efc1
    18 QCoreApplication::sendPostedEvents qcoreapplication.cpp 1472 0x7ffff552f453
    19 sendPostedEvents qcoreapplication.h 236 0x7ffff555abd3
    20 postEventSourceDispatch qeventdispatcher_glib.cpp 280 0x7ffff555abd3
    ... <More>

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.