[udp] Register socket consumption for CONFIG_LWIP_MAX_SOCKETS#14068
[udp] Register socket consumption for CONFIG_LWIP_MAX_SOCKETS#14068
Conversation
The UDP component creates up to 2 sockets (broadcast + listen) but did not register them with the socket consumption API. This could cause CONFIG_LWIP_MAX_SOCKETS to be set too low on ESP32 IDF. Closes #14031
|
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#14068
components: [udp]
refresh: 1h(Added by the PR bot) |
|
👋 Hi there! I've automatically requested reviews from codeowners based on the files changed in this PR. @clydebarrow - You've been requested to review this PR as codeowner(s) of 1 file(s) that were modified. Thanks for your time! 🙏 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #14068 +/- ##
=======================================
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:
|
There was a problem hiding this comment.
Pull request overview
Registers UDP component socket usage so ESP32 builds can correctly auto-size CONFIG_LWIP_MAX_SOCKETS, preventing runtime socket exhaustion (notably when UDP is used for syslog and similar features).
Changes:
- Add a config-validation hook to register UDP’s worst-case socket consumption (2 sockets).
- Wrap
udp’sCONFIG_SCHEMAincv.All(...)to run the socket consumer registration during validation.
Memory Impact AnalysisComponents:
This analysis runs automatically when components change. Memory usage is measured from a representative test configuration. |
|
Thanks |
What does this implement/fix?
The UDP component creates up to 2 sockets (
broadcast_socket_+listen_socket_) on ESP32 IDF but did not register them with the socket consumption API. This could causeCONFIG_LWIP_MAX_SOCKETSto be set too low, leading to socket exhaustion at runtime.Note on SNTP: LWIP has two layers: raw PCBs (
udp_new()/udp_sendto(), governed byCONFIG_LWIP_MAX_UDP_PCBS) and the BSD socket API (socket()/bind(), governed byCONFIG_LWIP_MAX_SOCKETS). The SNTP component callsesp_sntp_init()which internally uses a raw UDP PCB, not the socket API, so it does not consume from the socket pool and does not need socket registration.Note on syslog: The syslog component uses its parent UDP component's socket, so it is already covered by this change.
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: