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.
Este commit está contenido en:
Valentin V. Bartenev
2026-05-08 20:22:18 +03:00
padre 47f41847ac
commit ce510738d5
Se han modificado 2 ficheros con 3 adiciones y 3 borrados
+2 -2
Ver fichero
@@ -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");
}
}
+1 -1
Ver fichero
@@ -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; }