Skip to content

[web_server] Double socket allocation to prevent connection exhaustion#14067

Merged
bdraco merged 1 commit intodevfrom
web-server-bump-sockets
Feb 19, 2026
Merged

[web_server] Double socket allocation to prevent connection exhaustion#14067
bdraco merged 1 commit intodevfrom
web-server-bump-sockets

Conversation

@bdraco
Copy link
Member

@bdraco bdraco commented Feb 19, 2026

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

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Developer breaking change (an API change that could break external components)
  • Code quality improvements to existing code or addition of tests
  • Other

Related issue or feature (if applicable):

Pull request in esphome-docs with documentation (if applicable):

  • N/A (internal change, no user-facing configuration)

Test Environment

  • ESP32
  • ESP32 IDF
  • ESP8266
  • RP2040
  • BK72xx
  • RTL87xx
  • LN882x
  • nRF52840

Example entry for config.yaml:

# No configuration changes needed - automatic socket allocation
web_server:

Checklist:

  • The code change is tested and works locally.
  • Tests have been added to verify that the new code works (under tests/ folder).

If user exposed functionality or configuration variables are added/changed:

  • N/A - no user-facing changes

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.
Copilot AI review requested due to automatic review settings February 19, 2026 00:19
@github-actions
Copy link
Contributor

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-commenter
Copy link

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.11%. Comparing base (bd055e7) to head (3db34b4).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions
Copy link
Contributor

Memory Impact Analysis

Components: web_server
Platform: esp8266-ard

Metric Target Branch This PR Change
RAM 32,812 bytes 32,812 bytes ➡️ +0 bytes (0.00%)
Flash 413,049 bytes 413,049 bytes ➡️ +0 bytes (0.00%)

Note: This analysis measures static RAM and Flash usage only (compile-time allocation).
Dynamic memory (heap) cannot be measured automatically.
⚠️ You must test this PR on a real device to measure free heap and ensure no runtime memory issues.

This analysis runs automatically when components change. Memory usage is measured from a representative test configuration.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

@bdraco
Copy link
Member Author

bdraco commented Feb 19, 2026

Thanks

@bdraco bdraco merged commit 3b869f1 into dev Feb 19, 2026
44 checks passed
@bdraco bdraco deleted the web-server-bump-sockets branch February 19, 2026 01:01
@swoboda1337 swoboda1337 mentioned this pull request Feb 20, 2026
@github-actions github-actions bot locked and limited conversation to collaborators Feb 21, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

httpd: httpd_accept_conn: error in accept (23)

4 participants