diff --git a/esphome/components/libretiny/__init__.py b/esphome/components/libretiny/__init__.py index f6679e2456..1a424b653f 100644 --- a/esphome/components/libretiny/__init__.py +++ b/esphome/components/libretiny/__init__.py @@ -316,6 +316,7 @@ def _configure_lwip(config: dict) -> None: socket.get_socket_counts() with minimums of 8 TCP / 6 UDP. """ from esphome.components.socket import ( + MIN_TCP_LISTEN_SOCKETS, MIN_TCP_SOCKETS, MIN_UDP_SOCKETS, get_socket_counts, @@ -328,8 +329,8 @@ def _configure_lwip(config: dict) -> None: tcp_sockets = max(MIN_TCP_SOCKETS, raw_tcp) udp_sockets = max(MIN_UDP_SOCKETS, raw_udp) # Listening sockets — registered by components (api, ota, web_server_base, etc.) - # Not all components register yet, so ensure a minimum of 2 (api + ota baseline). - listening_tcp = max(raw_tcp_listen, 2) + # Not all components register yet, so ensure a minimum for baseline operation. + listening_tcp = max(MIN_TCP_LISTEN_SOCKETS, raw_tcp_listen) # TCP_SND_BUF: ESPAsyncWebServer allocates malloc(tcp_sndbuf()) per # response chunk. At 10×MSS=14.6KB (BK default) this causes OOM (#14095). diff --git a/esphome/components/socket/__init__.py b/esphome/components/socket/__init__.py index b8f971fd05..572e7993b9 100644 --- a/esphome/components/socket/__init__.py +++ b/esphome/components/socket/__init__.py @@ -21,12 +21,14 @@ KEY_SOCKET_CONSUMERS_TCP = "socket_consumers_tcp" KEY_SOCKET_CONSUMERS_UDP = "socket_consumers_udp" KEY_SOCKET_CONSUMERS_TCP_LISTEN = "socket_consumers_tcp_listen" -# Recommended minimum socket counts to ensure headroom. +# Recommended minimum socket counts. # Platforms should apply these (or their own) on top of get_socket_counts(). -# TCP: api(3) = 3 base, +5 headroom for ota-transfer/web_server/other. -# UDP: dhcp(1) + dns(1) + mdns(2) + wake_loop(1) = 5 base, +1 headroom. +# These cover minimal configs (e.g. api-only without web_server). +# When web_server is present, its 5 registered sockets push past the TCP minimum. MIN_TCP_SOCKETS = 8 MIN_UDP_SOCKETS = 6 +# Minimum listening sockets — at least api + ota baseline. +MIN_TCP_LISTEN_SOCKETS = 2 # Wake loop threadsafe support tracking KEY_WAKE_LOOP_THREADSAFE_REQUIRED = "wake_loop_threadsafe_required"