Skip to content

fix(api): improve connection resilience and handle connection resets - #61

Closed
tst-038 wants to merge 1 commit into
klejejs:mainfrom
tst-038:fix/connection-reset-resilience
Closed

tst-038 wants to merge 1 commit into
klejejs:mainfrom
tst-038:fix/connection-reset-resilience

Conversation

@tst-038

@tst-038 tst-038 commented Sep 9, 2026

Copy link
Copy Markdown

Summary

Resolves unhandled requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer')) when communicating with Thermia Online cloud during register writes or transient connection drops.

Details

  • Added a 15-second timeout to all HTTP requests.
  • Added a _request_with_retry wrapper that catches socket disconnects (ConnectionResetError, ConnectionError, Timeout).
  • When a connection drops, the broken session is closed and a fresh session is created before retrying the call.
  • HTTP status errors (like 400 or 500) are not retried—only actual transport/socket disconnects trigger a retry.
  • Added a unit test (test_retry_resilience.py) simulating a socket reset during a POST to ensure it recovers and succeeds.

- Add request timeout (15s) across all HTTP calls
- Implement _request_with_retry to recover from dropped sockets and ConnectionResetError
- Close dead session pools and recreate session on network drop
- Add unit test for retry resilience
@janfryauf

Copy link
Copy Markdown

Thanks for working on this. I ran into the same hang (klejejs/ha-thermia-heat-pump-integration#147) and opened #63 with only the timeout part: a default timeout on the session and fewer retries, about 20 lines.

I kept it separate because this PR also retries requests that aren't safe to repeat (the SelfAsserted login POST, the single-use auth-code exchange and register writes, so a write to the heat pump could be sent twice), and it changes __set_register_value to raise on non-200 responses. Both PRs edit the same lines, so only one can go in as is. Happy to close mine if you'd rather narrow this one down to the timeout.

@tst-038

tst-038 commented Oct 2, 2026

Copy link
Copy Markdown
Author

Thanks for the feedback! Looking at your PR #63, using ThermiaSession to set the default timeout and letting urllib3.Retry handle safe GET retries is definitely the cleaner and more idiomatic approach.

Let's go ahead with your PR #63 for the timeout fix.

I'll close this PR and open a small, separate PR specifically for __set_register_value raising on failure so it can cleanly pair with ha-thermia-heat-pump-integration#146
without mixing concerns. Thanks again!

@tst-038 tst-038 closed this Oct 2, 2026
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.

2 participants