feat(client): add connect_timeout and retry on httpx.ConnectTimeout - #1324
Draft
fatih-acar wants to merge 1 commit into
Draft
feat(client): add connect_timeout and retry on httpx.ConnectTimeout#1324fatih-acar wants to merge 1 commit into
fatih-acar wants to merge 1 commit into
Conversation
The SDK passed a single integer timeout to httpx, which applied it to the connect phase as well, so an unreachable address consumed the whole request budget (60s by default) before failing. A new connect_timeout setting (default 10s, INFRAHUB_CONNECT_TIMEOUT) now bounds the TCP/TLS handshake on every request path, capped by the per-request timeout. httpx.ConnectTimeout is not a NetworkError, so it escaped the ServerNotReachableError wrapping and was never retried. It is now treated like any other connection failure and retried when retry_on_failure is enabled, which lets endpoints published through DNS round robin fall over to the next address. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Deploying infrahub-sdk-python with
|
| Latest commit: |
2a84404
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://a4982fb9.infrahub-sdk-python.pages.dev |
| Branch Preview URL: | https://fac-dns-round-robin-5x8wr.infrahub-sdk-python.pages.dev |
Codecov Report✅ All modified and coverable lines are covered by tests. @@ Coverage Diff @@
## stable #1324 +/- ##
==========================================
+ Coverage 84.24% 84.36% +0.12%
==========================================
Files 147 147
Lines 13068 13050 -18
Branches 1940 1930 -10
==========================================
+ Hits 11009 11010 +1
+ Misses 1494 1478 -16
+ Partials 565 562 -3
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 1 file with indirect coverage changes 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
An Infrahub endpoint that does not answer the TCP or TLS handshake used to hold every SDK request for the full request timeout (60 seconds by default) and then fail with a raw
httpx.ConnectTimeoutthatretry_on_failurenever retried. This PR makes the connect phase fail fast and treats a connect timeout like any other connection failure, so clients behind a DNS round robin or a flapping endpoint recover quickly instead of stalling.Key Changes
connect_timeoutsetting (default 10 seconds,INFRAHUB_CONNECT_TIMEOUT) bounds the TCP/TLS handshake on every request path: regular requests, multipart uploads and streaming downloads, on both the async and sync clients. It never exceeds the per-requesttimeout.httpx.ConnectTimeoutis now raised asServerNotReachableError, soretry_on_failureretries it and each retry re-resolves DNS.timeoutsetting's description now states what it covers (read, write and pool phases) instead of calling itself a "connection timeout". No behaviour change.Documentation Updates
docs/docs/python-sdk/reference/config.mdxregenerated with the new setting.changelog/(one added, one fixed).Test Plan
uv run pytest tests/unit/sdk/test_connect_timeout.pycovers the config default and validation, the exact timeout httpx receives on every path for both clients, the cap by the request timeout, the error conversion, and retry throughexecute_graphql.uv run invoke format lint-codeanduv run invoke docs-validatepass locally.tests/unitsuite passes except three pre-existinginfrahubctltable-rendering failures that fail identically onstable.Summary by cubic
Fixes slow failures and non-retried connect timeouts in the Python SDK: an unreachable Infrahub endpoint no longer holds requests for the full request timeout, and
httpx.ConnectTimeoutnow retries whenretry_on_failureis enabled.connect_timeoutsetting (default 10 seconds,INFRAHUB_CONNECT_TIMEOUT) that bounds the TCP/TLS handshake on every request path, capped by the per-requesttimeout.httpx.ConnectTimeoutasServerNotReachableErrorsoretry_on_failureretries it and each retry re-resolves DNS, helping clients behind DNS round robin fall over to the next address quickly.timeoutsetting description to clarify it covers read, write, and pool phases only.Written for commit 2a84404. Summary will update on new commits.