Restart advertising fails with -ENOMEM

We have thousands of devices live in production and we sometimes encounter the situation that we cannot restart bluetooth advertising anymore after a connection attempt.

bt_le_adv_start will then return -12 (-ENOMEM). The only way to get out of this situation is a software reset of the device. This is done automatically now, so customer impact is limited. However we would really like to know why this is happening sometimes. 

We use the ble peripheral role and we allow only one connection (CONFIG_BT_MAX_CONN=1). bt_le_adv_start is called in a separate thread, so not in the connection callbacks.

The firmware is based on nRF Connect 3.1.1

Please find relevant code below:
BT_CONN_CB_DEFINE(conn_callbacks) = {
    .connected          = ble_connected,
    .disconnected       = ble_disconnected,
    .recycled           = ble_recycled};
    
static void ble_connected(bt_conn *conn, uint8_t err)
{
    if(current_connection != nullptr) {
        LOG_WRN("Already connected, unref old connection");
        bt_conn_unref(current_connection);
    }

    if(err != 0) {
        LOG_WRN("Connection failed (err %d), restart advertising", err);
        restart_advertising();
        return;
    }

    current_connection = bt_conn_ref(conn);
}

static void ble_disconnected(bt_conn *conn, uint8_t reason)
{
    if(current_connection != nullptr) {
        bt_conn_unref(current_connection);
        current_connection = nullptr;
    }
}

static void ble_recycled()
{
    LOG_INF("BLE recycled, restart advertising");

    restart_advertising();
}    


Any suggestions to fix this issue for real so we can remove the workaround?
Parents
  • Hi Bert,

    -12 (-ENOMEM) might be occurring because there might be some overlapping start sequences.

    Accidently you might be trying to start a new advertising context, before the previous one has stopped completely.

    Maybe you can take a look at the solution mentioned in this ticket.

    -Priyanka

  • Hi  thanks for your response!

    I will investigate the ticket you mentioned. But it is still weird that you can only get out of this situation with a reset of the device, right? I can imagine that I will get errors if I try to start or update advertising when it is still busy, but I would expect it to be working again if I try a little bit later. That's not what happening, once I will get the -ENOMEM error, the only way to get out of it is a reset of the device. Is this a known issue? 

Reply
  • Hi  thanks for your response!

    I will investigate the ticket you mentioned. But it is still weird that you can only get out of this situation with a reset of the device, right? I can imagine that I will get errors if I try to start or update advertising when it is still busy, but I would expect it to be working again if I try a little bit later. That's not what happening, once I will get the -ENOMEM error, the only way to get out of it is a reset of the device. Is this a known issue? 

Children
Related