diff --git a/nimble/host/src/ble_gap.c b/nimble/host/src/ble_gap.c index 4dbf9ef51..10847a157 100644 --- a/nimble/host/src/ble_gap.c +++ b/nimble/host/src/ble_gap.c @@ -1800,8 +1800,6 @@ ble_gap_conn_broken(uint16_t conn_handle, int reason) ble_gap_event_connect_call(conn_handle, BLE_HS_EAGAIN); } - ble_hs_atomic_conn_delete(conn_handle); - ble_hs_lock(); conn = ble_hs_conn_find(conn_handle); if (conn != NULL) { @@ -1812,6 +1810,8 @@ ble_gap_conn_broken(uint16_t conn_handle, int reason) } ble_hs_unlock(); + ble_hs_atomic_conn_delete(conn_handle); + event.type = BLE_GAP_EVENT_DISCONNECT; event.disconnect.reason = reason;