QtBluetoothSocket write() crashes on Android after sending a few messages



  • Hello everyone,

    I'm having a hard-to-debug problem with Qt Bluetooth on Android. The objective is to connect two Android devices (client/server) via RFCOMM, but I use a PC for testing in development because deploying to a single device is slow enough. Anyway, my code works without problems on PC (Linux, BlueZ 5) in client and server roles. Android works as a client, but when it acts as the server, it crashes after a certain number of writes to QBluetoothSocket; the error signal is SIGBUS.

    What I'm doing in my server code is:

    • waiting until a client connects
    • upon connection, firing a single shot QTimer that writes 1024 bytes to the socket if it is open and valid
    • when the bytesWritten signal is fired, I write another 1024 bytes to the socket if it is still open, etc.

    On the 1620th iteration of that (I don't know why, but) it crashes when calling a JNI method, outputstream.write. There is no exception, it just crashes.

    I can provide my app code if needed, but it's not very cleaned up at the moment due to this; also, building it requires some manual steps, like downloading GStreamer Android binaries. I already started writing a smaller repro that anybody willing to help could build and run quickly, but it's not complete yet.

    Can anybody knowledgeable with QtBluetooth tell me why that is happening?

    Edit: Since I haven't had time to write a minimal repro case until now (and it looks like it might take a longer while), I'm posting some code snippets from my application so in the hope that somebody can tell me whether I'm doing something blatantly wrong or something else is at fault.

    void ConnectionManager::clientConnected()
    {
        this->socket = btServer.nextPendingConnection();
    
       //...
       //connect other socket functoions (omitted)
       //...
    
        QObject::connect(socket, &QBluetoothSocket::bytesWritten, this, &ConnectionManager::bytesWritten, Qt::UniqueConnection);
    
        QTimer::singleShot(1000, this, &ConnectionManager::startSending);
    }
    
    void ConnectionManager::startSending()
    {
        //first write, subsequent ones continue in byteswritten
        Q_ASSERT(socket->isOpen());
        qint64 bytesWritten = socket->write(testdata, 1024);
        Q_ASSERT(bytesWritten == 1024);
    }
    
    void ConnectionManager::bytesWritten(qint64 bytes)
    {
        if (socket != nullptr && socket->isOpen())
        {
            qint64 bytesWritten = socket->write(testdata, 1024);
        }
    }
    

    By the way, I could also upload tombstone files (Android crash dumps) from a test run if needed/helpful.


Log in to reply
 

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