Skip to content

Fix coordinator stalling by adding HTTP request timeouts - #39

Open
timstoop wants to merge 2 commits into
Sikerdebaard:mainfrom
timstoop:main
Open

Fix coordinator stalling by adding HTTP request timeouts#39
timstoop wants to merge 2 commits into
Sikerdebaard:mainfrom
timstoop:main

Conversation

@timstoop

@timstoop timstoop commented Dec 8, 2025

Copy link
Copy Markdown

Problem

The ducopy library doesn't support timeout parameters on HTTP requests, causing the coordinator to hang indefinitely when the DucoBox device doesn't respond. This results in entities stopping updates for hours until the integration is manually reloaded.

Observed Behavior

When the DucoBox device becomes unresponsive (network issues, device busy, etc.), the coordinator silently stalls:

  • Sensors stop updating but retain their last value (no "unavailable" state)
  • No errors are logged
  • Integration remains stuck until manually reloaded

Root Cause

The ducopy library's DucoUrlSession extends requests.Session but doesn't set timeouts on HTTP calls. When super().request() is called without a timeout parameter, requests can hang indefinitely.

Solution

This PR adds a custom TimeoutHTTPAdapter that sets a default timeout of (SCAN_INTERVAL - 5 seconds) to all HTTP requests:

  • Requests timeout before the next update cycle begins (prevents request stacking)
  • Failed requests raise proper exceptions caught by the coordinator
  • Entities go unavailable on timeout (proper error handling)
  • Next update cycle automatically retries
  • Timeout is dynamically calculated from SCAN_INTERVAL for maintainability

Changes

  • Added TimeoutHTTPAdapter class that extends HTTPAdapter with default timeout
  • Modified DucoboxCoordinator.__init__ to mount the timeout adapter on both http:// and https://
  • Timeout set to 55 seconds (60s SCAN_INTERVAL - 5s buffer)

Tim Stoop and others added 2 commits December 8, 2025 09:36
The ducopy library doesn't support timeout parameters on HTTP requests,
causing the coordinator to hang indefinitely when the DucoBox device
doesn't respond. This results in entities stopping updates for hours
until the integration is manually reloaded.

This fix adds a custom TimeoutHTTPAdapter that sets a default timeout
of (SCAN_INTERVAL - 5s) to all HTTP requests, ensuring:
- Requests timeout before the next update cycle begins
- Failed requests are properly caught and logged as UpdateFailed
- Entities go unavailable on timeout instead of silently stalling
- Next update cycle can retry after a failed request

Timeout is dynamically calculated based on SCAN_INTERVAL configuration
for maintainability.

Fixes coordinator stalls observed in production where sensors would
stop updating for 6+ hours when the device became unresponsive.
Fixes 7+ hour hangs by implementing dual timeout defense:
- Primary: asyncio.wait_for() wrapper (110s timeout) on all executor jobs
- Secondary: TimeoutSSLAdapter (55s HTTP timeout) preserving SSL handling
- Write operations: 30s timeout for node value/state changes

Key changes:
- Replace TimeoutHTTPAdapter with TimeoutSSLAdapter to preserve ducopy's SSL context
- Wrap all async_add_executor_job calls with asyncio.wait_for()
- Add comprehensive logging: endpoint timing, errors with stack traces
- Add timeout constants to const.py for maintainability

This covers DNS, TCP, SSL handshake, and HTTP timeouts that were previously
bypassing the adapter-only approach.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@basdenooijer

Copy link
Copy Markdown

Nice fix! I run into this issue a lot, so hopefully this can be merged soon.

@halfa

halfa commented May 9, 2026

Copy link
Copy Markdown

Sikerdebaard/ducopy#18 adds a 15s timeout in the underlying library, which is likely more robust

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants