Skip to content

feat(client): add connect_timeout and retry on httpx.ConnectTimeout - #1324

Draft
fatih-acar wants to merge 1 commit into
stablefrom
fac/dns-round-robin-5x8wr
Draft

feat(client): add connect_timeout and retry on httpx.ConnectTimeout#1324
fatih-acar wants to merge 1 commit into
stablefrom
fac/dns-round-robin-5x8wr

Conversation

@fatih-acar

@fatih-acar fatih-acar commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

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.ConnectTimeout that retry_on_failure never 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

  • A new connect_timeout setting (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-request timeout.
  • httpx.ConnectTimeout is now raised as ServerNotReachableError, so retry_on_failure retries it and each retry re-resolves DNS.
  • The timeout setting'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.mdx regenerated with the new setting.
  • Two changelog fragments in changelog/ (one added, one fixed).

Test Plan

  • uv run pytest tests/unit/sdk/test_connect_timeout.py covers 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 through execute_graphql.
  • uv run invoke format lint-code and uv run invoke docs-validate pass locally.
  • The full tests/unit suite passes except three pre-existing infrahubctl table-rendering failures that fail identically on stable.

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.ConnectTimeout now retries when retry_on_failure is enabled.

  • Adds a connect_timeout setting (default 10 seconds, INFRAHUB_CONNECT_TIMEOUT) that bounds the TCP/TLS handshake on every request path, capped by the per-request timeout.
  • Raises httpx.ConnectTimeout as ServerNotReachableError so retry_on_failure retries it and each retry re-resolves DNS, helping clients behind DNS round robin fall over to the next address quickly.
  • Updates the timeout setting description to clarify it covers read, write, and pool phases only.

Written for commit 2a84404. Summary will update on new commits.

Review in cubic

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>
@fatih-acar fatih-acar added the type/feature New feature or request label Sep 4, 2026
@github-actions github-actions Bot added the type/documentation Improvements or additions to documentation label Sep 4, 2026
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying infrahub-sdk-python with  Cloudflare Pages  Cloudflare Pages

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

View logs

@codecov

codecov Bot commented Sep 4, 2026

Copy link
Copy Markdown

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     
Flag Coverage Δ
integration-tests 39.10% <25.00%> (-0.09%) ⬇️
python-3.10 57.18% <75.00%> (+0.17%) ⬆️
python-3.11 57.19% <75.00%> (+0.19%) ⬆️
python-3.12 57.18% <75.00%> (+0.17%) ⬆️
python-3.13 57.19% <75.00%> (+0.19%) ⬆️
python-3.14 57.19% <75.00%> (+0.19%) ⬆️
python-filler-3.12 23.69% <25.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
infrahub_sdk/client.py 81.13% <100.00%> (+1.37%) ⬆️
infrahub_sdk/config.py 91.51% <100.00%> (+0.05%) ⬆️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 6 files

Re-trigger cubic

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

Labels

type/documentation Improvements or additions to documentation type/feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant