[web_server] Double socket allocation to prevent connection exhaustion#14067
[web_server] Double socket allocation to prevent connection exhaustion#14067
Conversation
Browsers open multiple concurrent connections for page resources, SSE event streams, and POST requests for entity control. POST connections may linger before closing, causing httpd_accept_conn errors (ENFILE) when the socket pool is too small.
|
To use the changes from this PR as an external component, add the following to your ESPHome configuration YAML file: external_components:
- source: github://pr#14067
components: [web_server]
refresh: 1h(Added by the PR bot) |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #14067 +/- ##
=======================================
Coverage 74.11% 74.11%
=======================================
Files 55 55
Lines 11589 11589
Branches 1578 1578
=======================================
Hits 8589 8589
Misses 2598 2598
Partials 402 402 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Memory Impact AnalysisComponents:
This analysis runs automatically when components change. Memory usage is measured from a representative test configuration. |
There was a problem hiding this comment.
Pull request overview
Adjusts the web_server component’s declared socket consumption so ESP32 builds can size CONFIG_LWIP_MAX_SOCKETS with enough headroom for typical browser concurrency (resources + SSE + control POSTs), reducing connection exhaustion scenarios.
Changes:
- Increase web server socket consumer registration from 3 to 6.
- Update inline comments to reflect modern browser connection patterns (SSE + resource fetches + POST control requests).
|
Thanks |
What does this implement/fix?
Double the web_server socket allocation from 3 to 6 to prevent
httpd_accept_conn: error in accept (23)errors.Browsers open multiple concurrent connections for page resources, the SSE event stream, and POST requests for entity control (toggle, slider changes, etc.). The POST connections may linger before closing, quickly exhausting the socket pool when only 3 sockets are allocated. This causes ENFILE errors and the web server becomes unresponsive.
Changing from 3 (1 listening + 2 client) to 6 (1 listening + 5 client) provides enough headroom for concurrent SSE + POST operations.
fixes #13645
Types of changes
Related issue or feature (if applicable):
Pull request in esphome-docs with documentation (if applicable):
Test Environment
Example entry for
config.yaml:Checklist:
tests/folder).If user exposed functionality or configuration variables are added/changed: