From b877b4a57ec7e2355afe8085829d1f9eef613423 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 19 Mar 2026 18:54:22 -1000 Subject: [PATCH] [web_server] Increase httpd task stack size to prevent stack overflow The SerializationBuffer introduced in #13625 places a 640-byte buffer on the stack. When handling HTTP requests on the ESP-IDF httpd task (which has a default stack of 4096 bytes), the deep call chain from handleRequest through JSON serialization and lwip_send can overflow. Increase the httpd task stack by 256 bytes to restore headroom. Fixes #14991 --- esphome/components/web_server_idf/web_server_idf.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/esphome/components/web_server_idf/web_server_idf.cpp b/esphome/components/web_server_idf/web_server_idf.cpp index 60816fc6dd2..8b8037a4791 100644 --- a/esphome/components/web_server_idf/web_server_idf.cpp +++ b/esphome/components/web_server_idf/web_server_idf.cpp @@ -121,7 +121,11 @@ void AsyncWebServer::begin() { if (this->server_) { this->end(); } + // Default httpd stack is 4096. Increase to accommodate SerializationBuffer's + // 640-byte stack buffer used by web_server JSON request handlers. + constexpr size_t HTTPD_STACK_SIZE = 4096 + 256; httpd_config_t config = HTTPD_DEFAULT_CONFIG(); + config.stack_size = HTTPD_STACK_SIZE; config.server_port = this->port_; config.uri_match_fn = [](const char * /*unused*/, const char * /*unused*/, size_t /*unused*/) { return true; }; // Always enable LRU purging to handle socket exhaustion gracefully.