This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

"Disconnected while allocating context" inside bt_gatt_notify_cb and subsequent bt buffer allocation errors

I run a custom multilink BLE service server on nRF9160 DK.

After about 20 minutes of repeated connecting, data exchange and disconnecting from 4 (only four) BLE devices I get this log:

[00:18:43.188,781] <wrn> bt_conn: Disconnected while allocating context

It appears deep inside bt_gatt_notify_cb() call stack when I'm trying to publish data to Notify char

if (bt_gatt_is_subscribed(conn, attr, BT_GATT_CCC_NOTIFY)) {
        int err = bt_gatt_notify_cb(conn, &params);
}

Both before (bt_gatt_is_subscribed()) and inside the call there are checks for conn->state to be BT_CONN_CONNECTED, but when it comes to context allocation is becomes BT_CONN_DISCONNECT_COMPLETE.

Soon after it looks like this:

[00:22:50.196,044] <wrn> bt_conn: Unable to allocate buffer within timeout
[00:22:50.196,044] <err> bt_l2cap: Unable to allocate buffer for op 0x12
[00:23:13.196,655] <wrn> bt_conn: Unable to allocate buffer within timeout
[00:23:13.196,655] <err> bt_att: Unable to allocate buffer for op 0x07
[00:23:43.196,746] <wrn> bt_conn: Unable to allocate buffer within timeout
[00:23:43.196,746] <err> bt_att: Unable to allocate buffer for op 0x01
[00:23:43.197,662] <inf> : Connected F9:BD:FC:A5:A0:B3 (random)
[00:23:43.197,814] <wrn> bt_att: Not connected
[00:23:43.197,967] <inf> : Disconnected: reason 19)
[00:23:50.197,631] <wrn> bt_conn: Unable to allocate buffer within timeout
[00:23:50.197,631] <err> bt_l2cap: Unable to allocate buffer for op 0x12
[00:24:13.197,906] <wrn> bt_conn: Unable to allocate buffer within timeout
[00:24:13.197,906] <err> bt_att: Unable to allocate buffer for op 0x01
[00:24:13.198,913] <inf> : Connected E2:3B:8B:13:08:72 (random)
[00:24:13.199,523] <inf> : Disconnected: reason 19)
[00:24:20.198,883] <wrn> bt_conn: Unable to allocate buffer within timeout
[00:24:20.198,883] <err> bt_l2cap: Unable to allocate buffer for op 0x12
[00:24:43.199,462] <wrn> bt_conn: Unable to allocate buffer within timeout
[00:24:43.199,462] <err> bt_att: Unable to allocate buffer for op 0x07
[00:25:13.199,554] <wrn> bt_conn: Unable to allocate buffer within timeout
[00:25:13.199,554] <err> bt_att: Unable to allocate buffer for op 0x01

How do I handle this error on the server side, or better yet, prevent it? What causes this?

  • Hi,

    The problem is that the peer devices are sending disconnect requests to your device for some reason. This is why the subsequent buffer allocations fail in the Bluetooth stack (these are more warning messages for debugging purposes, and can be ignored).

    Do you have control over the FW on the other side of the link?

  • I know that initially the problem is caused by peer device disconnecting abruptly.

    My question is how do I handle this unexpected disconnection and its consequences, since it could happen for many different reasons, whether I have control over firmware or not. Is there a way to fix the buffer allocation error on the go?

  • The failing to allocate buffers is a direct result of the disconnect, and they are debug warnings, not actual errors. You can ignore them.

Related