From 6502b66afb8ce5e794fe81afac997fb6ea8612d5 Mon Sep 17 00:00:00 2001 From: Rahul Tank Date: Fri, 18 Jul 2025 08:00:01 +0530 Subject: [PATCH] fix(nimble): Add packet allocation retry for limited iteration --- .../host/nimble/esp-hci/src/esp_nimble_hci.c | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/components/bt/host/nimble/esp-hci/src/esp_nimble_hci.c b/components/bt/host/nimble/esp-hci/src/esp_nimble_hci.c index 517eaa74aa..35fe525c85 100644 --- a/components/bt/host/nimble/esp-hci/src/esp_nimble_hci.c +++ b/components/bt/host/nimble/esp-hci/src/esp_nimble_hci.c @@ -162,19 +162,33 @@ static void ble_hci_rx_acl(uint8_t *data, uint16_t len) struct os_mbuf *m = NULL; int rc; int sr; + + int retry_count = 1; + if (len < BLE_HCI_DATA_HDR_SZ || len > MYNEWT_VAL(BLE_TRANSPORT_ACL_SIZE)) { return; } - do { + + do { m = ble_transport_alloc_acl_from_ll(); if (!m) { - esp_rom_printf("Failed to allocate buffer, retrying "); - /* Give some time to free buffer and try again */ - vTaskDelay(1); + if (retry_count % 5) { + esp_rom_printf("ACL buf alloc failed %d times\n", retry_count); + esp_rom_printf("Free ACL mbufs: %d\n", os_msys_num_free()); + } + + vTaskDelay(1); + retry_count++; + + if (retry_count >= 30) { + esp_rom_printf("MBUF alloc stuck"); + return; + } } - }while(!m); + } while (!m); + if ((rc = os_mbuf_append(m, data, len)) != 0) { esp_rom_printf("%s failed to os_mbuf_append; rc = %d", __func__, rc);