From b4b301dbbfc72cb5f398093c6264aef64a5a51a7 Mon Sep 17 00:00:00 2001 From: "Valentin V. Bartenev" Date: Wed, 6 May 2026 22:25:51 +0300 Subject: [PATCH] Web: prevent redirect server socket exhaustion from stale connections MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The HTTP redirect server has max_open_sockets = 2. A client that connects and then disappears silently (network drop, browser crash, mobile radio loss) leaves its socket occupying a slot indefinitely — the server has no way to detect the loss until it tries to write to the socket again. Enable lru_purge_enable on the redirect server so that when both slots are occupied by such stale connections, the least-recently-used one is evicted automatically to make room for a new incoming connection, rather than refusing it outright. Add a "Connection: close" header to the 302 response as a complementary measure. For well-behaved clients this triggers an immediate TCP teardown after the redirect is received, shrinking the window during which a connection can turn into a zombie. Together the two changes provide defence in depth: "Connection: close" prevents stale connections from forming in the first place; lru_purge_enable cleans them up when they do. --- src/helpers/web/WebPanelServer.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/helpers/web/WebPanelServer.cpp b/src/helpers/web/WebPanelServer.cpp index 130c3031..26d5bd19 100644 --- a/src/helpers/web/WebPanelServer.cpp +++ b/src/helpers/web/WebPanelServer.cpp @@ -2617,6 +2617,7 @@ bool WebPanelServer::start() { redirect_config.backlog_conn = 0; redirect_config.recv_wait_timeout = 10; redirect_config.send_wait_timeout = 10; + redirect_config.httpd.lru_purge_enable = true; redirect_config.stack_size = kWebServerStackSize; redirect_config.task_priority = tskIDLE_PRIORITY + 2; redirect_config.core_id = 0; @@ -2697,6 +2698,7 @@ esp_err_t WebPanelServer::handleHttpRedirect(httpd_req_t* req) { httpd_resp_set_status(req, "302 Found"); httpd_resp_set_hdr(req, "Location", location); httpd_resp_set_hdr(req, "Cache-Control", "no-store"); + httpd_resp_set_hdr(req, "Connection", "close"); return httpd_resp_send(req, "", 0); }