From 31771da92c41320960516f8f0d3b67716b4c31be Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 9 Aug 2026 17:03:09 -0500 Subject: [PATCH] Address review: gate the cache clean where the paths converge The stack-down settle skipped release_services() locally, but its report routes into the wrapper's reset which calls it anyway - the warn survived. Gating the clean on an active stack inside release_services() covers every path, and the stack-down branch goes back to the plain call. --- .../bluetooth_connection_bluedroid.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/esphome/components/bluetooth_connection/bluetooth_connection_bluedroid.cpp b/esphome/components/bluetooth_connection/bluetooth_connection_bluedroid.cpp index e40e72ee11..e62ec103d3 100644 --- a/esphome/components/bluetooth_connection/bluetooth_connection_bluedroid.cpp +++ b/esphome/components/bluetooth_connection/bluetooth_connection_bluedroid.cpp @@ -49,10 +49,7 @@ void BluedroidGattClient::loop() { // frees its slot, then re-register the app on the next enable. auto down_st = this->state(); if (down_st != ClientState::IDLE && down_st != ClientState::INIT) { - // The dying stack invalidates its own cache; a cache_clean would just - // warn against a disabled stack. Reset the stream latches directly. - this->service_total_ = 0; - this->services_released_ = true; + this->release_services(); this->set_idle_(); this->listener_->on_connection_state(false, 0, ble_device_base::GATT_ERR_NOT_CONNECTED); } @@ -305,8 +302,11 @@ void BluedroidGattClient::release_services() { this->services_released_ = true; #ifndef CONFIG_BT_GATTC_CACHE_NVS_FLASH // A failed clean leaves a stale database the next connection could serve - // as authoritative; make it visible like every other IDF call here. - this->check_and_log_error_("esp_ble_gattc_cache_clean", esp_ble_gattc_cache_clean(this->remote_bda_)); + // as authoritative. A disabled stack invalidates its own cache; skip the + // meaningless call instead of warning on every OTA/ble.disable teardown. + if (esp32_ble::global_ble->is_active()) { + this->check_and_log_error_("esp_ble_gattc_cache_clean", esp_ble_gattc_cache_clean(this->remote_bda_)); + } #endif }