From 91ba3b587c8722d3ee1b28f7cfa3813245a6cb89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Proch=C3=A1zka?= <90197375+P-R-O-C-H-Y@users.noreply.github.com> Date: Wed, 3 Sep 2025 15:59:10 +0200 Subject: [PATCH] fix(zigbee): Add lock in scanNetworks to avoid race condition --- libraries/Zigbee/src/ZigbeeCore.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libraries/Zigbee/src/ZigbeeCore.cpp b/libraries/Zigbee/src/ZigbeeCore.cpp index 90b29cf9d0a..110b4bf2c93 100644 --- a/libraries/Zigbee/src/ZigbeeCore.cpp +++ b/libraries/Zigbee/src/ZigbeeCore.cpp @@ -515,8 +515,14 @@ void ZigbeeCore::scanNetworks(u_int32_t channel_mask, u_int8_t scan_duration) { log_e("Zigbee stack is not started, cannot scan networks"); return; } + if (_scan_status == ZB_SCAN_RUNNING) { + log_w("Scan already in progress, ignoring new scan request"); + return; + } log_v("Scanning Zigbee networks"); + esp_zb_lock_acquire(portMAX_DELAY); esp_zb_zdo_active_scan_request(channel_mask, scan_duration, scanCompleteCallback); + esp_zb_lock_release(); _scan_status = ZB_SCAN_RUNNING; }