From 5b624dcc6915c986717675f7a68f7456fe20ba5f Mon Sep 17 00:00:00 2001 From: shripad621git Date: Fri, 31 May 2024 12:06:28 +0530 Subject: [PATCH] Unregistering wifi and IP event handlers before factory reset to avoid random crashes due to post event queue failure --- src/platform/ESP32/ConfigurationManagerImpl.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/platform/ESP32/ConfigurationManagerImpl.cpp b/src/platform/ESP32/ConfigurationManagerImpl.cpp index 55c8758bb85fe7..80d750b931a191 100644 --- a/src/platform/ESP32/ConfigurationManagerImpl.cpp +++ b/src/platform/ESP32/ConfigurationManagerImpl.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #if CHIP_DEVICE_CONFIG_ENABLE_ETHERNET @@ -404,6 +405,19 @@ void ConfigurationManagerImpl::DoFactoryReset(intptr_t arg) { CHIP_ERROR err; + // Unregistering the wifi and IP event handlers from the esp_default_event_loop() + err = ESP32Utils::MapError(esp_event_handler_unregister(IP_EVENT, ESP_EVENT_ANY_ID, PlatformManagerImpl::HandleESPSystemEvent)); + if (err != CHIP_NO_ERROR) + { + ChipLogError(DeviceLayer, "Failed to unregister IP event handler"); + } + + err = ESP32Utils::MapError(esp_event_handler_unregister(WIFI_EVENT, ESP_EVENT_ANY_ID, PlatformManagerImpl::HandleESPSystemEvent)); + if (err != CHIP_NO_ERROR) + { + ChipLogError(DeviceLayer, "Failed to unregister wifi event handler"); + } + ChipLogProgress(DeviceLayer, "Performing factory reset"); // Erase all values in the chip-config NVS namespace.