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.
Tento commit je obsažen v:
Valentin V. Bartenev
2026-05-08 20:22:18 +03:00
rodič 47f41847ac
revize ce510738d5
2 změnil soubory, kde provedl 3 přidání a 3 odebrání
+2 -2
Zobrazit soubor
@@ -2645,9 +2645,9 @@ bool WebPanelServer::start() {
void WebPanelServer::stop() { void WebPanelServer::stop() {
stopRedirectServer(); stopRedirectServer();
if (_server != nullptr) { if (_server != nullptr) {
WEB_PANEL_LOG("server stopped");
httpd_ssl_stop(_server); httpd_ssl_stop(_server);
_server = nullptr; _server = nullptr;
WEB_PANEL_LOG("server stopped");
} }
_token[0] = 0; _token[0] = 0;
_last_activity_ms = 0; _last_activity_ms = 0;
@@ -2663,9 +2663,9 @@ bool WebPanelServer::hasSessionToken() const {
void WebPanelServer::stopRedirectServer() { void WebPanelServer::stopRedirectServer() {
if (_redirect_server != nullptr) { if (_redirect_server != nullptr) {
WEB_PANEL_LOG("redirect server stopped");
httpd_stop(_redirect_server); httpd_stop(_redirect_server);
_redirect_server = nullptr; _redirect_server = nullptr;
WEB_PANEL_LOG("redirect server stopped");
} }
} }
+1 -1
Zobrazit soubor
@@ -21,7 +21,7 @@ public:
void setNetworkStateProvider(NetworkStateProvider* network) { _network = network; } void setNetworkStateProvider(NetworkStateProvider* network) { _network = network; }
bool setWebEnabled(bool enabled); 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 setWebStatsEnabled(bool enabled);
bool isWebStatsEnabled() const { return _prefs.web_stats_enabled != 0; } bool isWebStatsEnabled() const { return _prefs.web_stats_enabled != 0; }