From ce510738d5f9d8c5ccdeab65633c4eb573950882 Mon Sep 17 00:00:00 2001 From: "Valentin V. Bartenev" Date: Fri, 8 May 2026 20:22:18 +0300 Subject: [PATCH] Web: delay WiFi shutdown and reorder stop logs This fixes accidental crash when disabling the web panel without an active MQTT uplink. When the web panel was disabled, isWebEnabled() immediately returned false. If no other network consumer was active, network.loop(false) tore down WiFi *before* web.loop() stopped the httpd server. Calling httpd_stop() while WiFi was being freed sometimes caused a LoadProhibited panic (ieee80211_output_do -> wifi_free). This only occurred when the server was stopped after WiFi teardown began. Fix by including _panel.isRunning() in isWebEnabled(): WiFi stays up for one extra iteration, so the server is stopped while the stack is still valid. Only on the next loop cycle does the network shut down. Additionally, move the "server stopped" and "redirect server stopped" log messages to after the actual httpd_stop() / httpd_ssl_stop() calls. This prevents a misleading "stopped" message if a crash happens during teardown. --- src/helpers/web/WebPanelServer.cpp | 4 ++-- src/helpers/web/WebService.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/helpers/web/WebPanelServer.cpp b/src/helpers/web/WebPanelServer.cpp index c87f0842..186057d8 100644 --- a/src/helpers/web/WebPanelServer.cpp +++ b/src/helpers/web/WebPanelServer.cpp @@ -2645,9 +2645,9 @@ bool WebPanelServer::start() { void WebPanelServer::stop() { stopRedirectServer(); if (_server != nullptr) { - WEB_PANEL_LOG("server stopped"); httpd_ssl_stop(_server); _server = nullptr; + WEB_PANEL_LOG("server stopped"); } _token[0] = 0; _last_activity_ms = 0; @@ -2663,9 +2663,9 @@ bool WebPanelServer::hasSessionToken() const { void WebPanelServer::stopRedirectServer() { if (_redirect_server != nullptr) { - WEB_PANEL_LOG("redirect server stopped"); httpd_stop(_redirect_server); _redirect_server = nullptr; + WEB_PANEL_LOG("redirect server stopped"); } } diff --git a/src/helpers/web/WebService.h b/src/helpers/web/WebService.h index be6aa43e..a875f16a 100644 --- a/src/helpers/web/WebService.h +++ b/src/helpers/web/WebService.h @@ -21,7 +21,7 @@ public: void setNetworkStateProvider(NetworkStateProvider* network) { _network = network; } bool setWebEnabled(bool enabled); - bool isWebEnabled() const { return _prefs.web_enabled != 0; } + bool isWebEnabled() const { return _prefs.web_enabled != 0 || _panel.isRunning(); } bool setWebStatsEnabled(bool enabled); bool isWebStatsEnabled() const { return _prefs.web_stats_enabled != 0; }