From 94d2ddf5071c8184c349394dead9762ac87d1067 Mon Sep 17 00:00:00 2001 From: "Valentin V. Bartenev" Date: Wed, 6 May 2026 22:14:28 +0300 Subject: [PATCH] Web: tune httpd config to reduce browser freezes on slow ESP32 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The ESP32 processes HTTP requests sequentially on a single task. Under load — generating chunked HTML pages, running commands, or serving sequential stats API calls — it can be slow to send data or loop back to accept the next request. The previous 2-second recv/send timeouts were too tight for this: the httpd layer would drop connections mid-transfer, causing the browser to hang or show incomplete pages. Raise recv_wait_timeout and send_wait_timeout from 2 s to 10 s on both the HTTPS and HTTP-redirect servers, giving the ESP32 enough headroom to finish generating and sending responses without the transport layer tearing down the connection prematurely. Set backlog_conn to 0 on both servers. With the previous backlog of 2, incoming connections completed the TCP handshake and queued in the kernel while the ESP32 was busy. The browser saw the connection as open but received no HTTP response, causing it to freeze indefinitely. With backlog 0 (lwIP minimum), connections that cannot be immediately accepted are refused outright, giving the browser a fast, recoverable error instead of a silent hang. Enable lru_purge_enable on the HTTPS server. Browsers hold keep-alive connections open for reuse. With max_open_sockets = 2, both slots can be occupied by idle keep-alive connections from the same session, blocking a new connection attempt entirely. LRU purge automatically closes the least-recently-used idle keep-alive connection to make room, ensuring the single client can always reconnect without a server restart. --- src/helpers/web/WebPanelServer.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/helpers/web/WebPanelServer.cpp b/src/helpers/web/WebPanelServer.cpp index fb51fea6..130c3031 100644 --- a/src/helpers/web/WebPanelServer.cpp +++ b/src/helpers/web/WebPanelServer.cpp @@ -2568,9 +2568,10 @@ bool WebPanelServer::start() { config.httpd.max_open_sockets = 2; config.httpd.max_uri_handlers = 7; config.httpd.max_resp_headers = 4; - config.httpd.backlog_conn = 2; - config.httpd.recv_wait_timeout = 2; - config.httpd.send_wait_timeout = 2; + config.httpd.backlog_conn = 0; + config.httpd.recv_wait_timeout = 10; + config.httpd.send_wait_timeout = 10; + config.httpd.lru_purge_enable = true; config.httpd.stack_size = kWebServerStackSize; config.httpd.task_priority = tskIDLE_PRIORITY + 2; config.httpd.core_id = 0; @@ -2613,9 +2614,9 @@ bool WebPanelServer::start() { redirect_config.max_open_sockets = 2; redirect_config.max_uri_handlers = 1; redirect_config.max_resp_headers = 4; - redirect_config.backlog_conn = 2; - redirect_config.recv_wait_timeout = 2; - redirect_config.send_wait_timeout = 2; + redirect_config.backlog_conn = 0; + redirect_config.recv_wait_timeout = 10; + redirect_config.send_wait_timeout = 10; redirect_config.stack_size = kWebServerStackSize; redirect_config.task_priority = tskIDLE_PRIORITY + 2; redirect_config.core_id = 0;