NimBLE-Arduino icon indicating copy to clipboard operation
NimBLE-Arduino copied to clipboard

ERROR "<< sendValue: failed to allocate mbuf" some time after the start of sending notifications. v2.2.3

Open truefalsenone opened this issue 10 months ago • 1 comments

Hello,

I am using the ESP32-C3. My project has a BLE-client and a BLE-server. The NimBLE-Arduino version is v2.2.3.

The BLE-server sends notifications with a payload of 40 bytes 2 times per second. However, after some time (about 50 minutes), the notifications stop being sent, and in the server log I see an error: "<< sendValue: failed to allocate mbuf."

NimBLECharacteristic.cpp

// Must re-create the data buffer on each iteration because it is freed by the calls bellow.
os_mbuf* om = ble_hs_mbuf_from_flat(value, length);
if (!om) {
    NIMBLE_LOGE(LOG_TAG, "<< sendValue: failed to allocate mbuf");
    return false;
}

If I reconnect, the notifications are successfully sent again. 70 KB are free in a heap all the time.

truefalsenone avatar Mar 21 '25 12:03 truefalsenone

You should wait until the onStatus callback is invoked (checking for success of the last notification, rc==0) before sending the next notification. The issue in this case is that there is a connection issue between the devices and each time a notification is sent it consumes a buffer but if that doesn't get sent then the buffer doesn't get freed.

h2zero avatar Mar 21 '25 17:03 h2zero