How do I fix "Unable to allocate buffer" error?

I had described my problem in my previous question.

In short, after a long time of a bunch of central BLE devices regularly connecting and disconnecting to my nRF52840 peripheral device  for data exchange the peripheral device fails to allocate buffers for subsequent connections and becomes unusable, the centrals try to connect but the peripheral won't let them anymore. I can't just ignore that.

The peripheral handles multiple connections at the same time.

How do I fix this? The only thing that works so far is rebooting the peripheral, but frequent and abrupt reboots are just not right. Is there a way to reset the buffers or BLE core or something to make the buffers allocate again? Or is there a way to prevent this from happening? Central devices have to disconnect and reconnect every time.

Parents
  • Hello,

    Please include the debug log here if you can. The memory should have been freed after the connection was terminated, so I am not sure what is happening here.

    Thanks,

    Vidar

Reply
  • Hello,

    Please include the debug log here if you can. The memory should have been freed after the connection was terminated, so I am not sure what is happening here.

    Thanks,

    Vidar

Children
  • I don't think I can provide internal debug logs for connections, when I add CONFIG_BT_DEBUG_CONN to prj.conf the amount of logs seem to cause the system to fault within seconds.

    This is to what extent I can share what's going on: connections, amount of data received on write char, amount of data written to notify char, disconnections. There are 5 central devices total.

    The error occurs when a central device connects and sends some data and the peripheral tries to reply.

    Everything above "my_custom_service_server: bt_gatt_notify_cb -128" is how it's supposed to work, and it does for about 15 minutes. Once bt_gatt_notify_cb returns -ENOTCONN (-128) the connections can't be established anymore. I check for connection twice before calling bt_gatt_notify_cb.


    I can get a few of occasional "bt_conn: Disconnected while allocating context" or "bt_att: Not connected" before the connection failures start, but subsequent connections are OK, so it doesn't always result in this error.