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:

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

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

Fullscreen
1
2
3
if (bt_gatt_is_subscribed(conn, attr, BT_GATT_CCC_NOTIFY)) {
int err = bt_gatt_notify_cb(conn, &params);
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

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:

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
[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
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

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