Add minimum interval between consecutive HTTP requests#4
Conversation
5196450 to
be01d05
Compare
|
Hi @amasolov, Thank you for the contribution. I would suggest we utilize the debounce globally during a request and not creating a new function that now does the same thing as the debounce. Since right now both the old debounce and new request internal both keep track of requests delays on commands (since commands utilize the same _request function). So for me I would suggest we keep the debounce but utilize it in the way you proposed in this PR. Kind regards, |
Move the existing debounce mechanism into _request() so it applies uniformly to all HTTP requests (reads and writes). Previously the debounce only gated read requests that followed a write command. Now every request waits at least _debounce_delay seconds since the previous request completed, giving the device's embedded web server time to recover between operations and preventing socket exhaustion under sustained polling. Changes: - _wait_for_debounce() now tracks _last_request_time (all requests) instead of only command times - Debounce is enforced inside _request(), removing per-method calls - _send_command() no longer separately tracks command time - _last_request_time is updated on errors so the delay is respected when the device is struggling
be01d05 to
5c80d5a
Compare
|
Thanks for the feedback! I've reworked this to use the existing Changes in this update:
The result is one clean mechanism: every request waits at least |
Summary
HDFury devices run an embedded web server with limited resources (similar to ESP32-class devices). When the Home Assistant integration polls for data every 60 seconds, it fires 4 HTTP GET requests in rapid succession (
brdinfo.ssi,infopage.ssi,confpage.ssi,cecpage.ssi). Over time, this rapid-fire pattern can exhaust available sockets on the device's embedded HTTP server, causing it to become unresponsive and eventually crash (requiring a power cycle to recover).This is the same class of issue seen in ESP-IDF based web servers (e.g. esphome/esphome#12481) where rapid polling without request spacing leads to
httpd_accept_conn: error in accept (23).Changes
_request_interval(default 1 second) to theHDFuryAPIclass that enforces a minimum delay between any two consecutive HTTP requests_request()so it covers all read and write operations uniformly_debounce_delay(which only gates reads after writes) is preserved unchanged_last_request_timeis updated even on errors, so the interval is still respected when the device is strugglingImpact
Testing
test_request_interval_spaces_consecutive_requests— confirms sleep when called too fasttest_request_interval_no_sleep_when_enough_time_elapsed— confirms no unnecessary delaytest_request_updates_last_request_time— confirms timestamp tracking