diff --git a/nimble/host/src/ble_gap.c b/nimble/host/src/ble_gap.c index 46da97043..5ef2f87ad 100644 --- a/nimble/host/src/ble_gap.c +++ b/nimble/host/src/ble_gap.c @@ -1693,8 +1693,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) { @@ -1705,6 +1703,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;