Skip to content

Forward uds, local_address and retries to proxied connections - #1172

Open
mbeijen wants to merge 1 commit into
pydantic:mainfrom
mbeijen:proxy-transport-options
Open

Forward uds, local_address and retries to proxied connections#1172
mbeijen wants to merge 1 commit into
pydantic:mainfrom
mbeijen:proxy-transport-options

Conversation

@mbeijen

@mbeijen mbeijen commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

When a proxy was configured, HTTPTransport and AsyncHTTPTransport
silently dropped uds, local_address and retries instead of forwarding
them to the underlying pool.

The gap ran deeper than the transport layer:

  • httpcore2.HTTPProxy accepted all three but its create_connection never
    handed them (or socket_options) to the proxy connections it built.
  • ConnectionPool(proxy=...) had the same gap in all three of its proxy
    branches.
  • SOCKSProxy accepted retries while the Socks5 connection had no retry
    logic at all.

Changes

  • Thread retries, local_address and uds through the forward and tunnel
    proxy connections down to the inner HTTPConnection.
  • Implement connect retries for Socks5 connections, mirroring the backoff
    behaviour of HTTPConnection (same exception set, same
    exponential_backoff sequence, same Trace("retry", ...)).
  • Forward the options from both transports. SOCKS proxies support retries
    only; uds, local_address and socket_options are not available there,
    now noted in the transports documentation.
  • Drop the local_address and uds entries from the SOCKSProxy docstring,
    which documented parameters the constructor does not accept.

Note that socket_options remains silently ignored for SOCKS proxies rather
than raising — that would be a behaviour change for anyone currently passing
the combination, so it is documented instead.

See #1160

Review in cubic

When a `proxy` was configured, `HTTPTransport` and `AsyncHTTPTransport`
silently dropped `uds`, `local_address` and `retries` instead of
forwarding them to the underlying pool. The gap ran deeper than the
transport layer: `httpcore2.HTTPProxy` accepted all three but its
`create_connection` never handed them (or `socket_options`) to the
proxy connections it built, `ConnectionPool(proxy=...)` had the same
gap in all three of its proxy branches, and `SOCKSProxy` accepted
`retries` while the Socks5 connection had no retry logic at all.

- Thread `retries`, `local_address` and `uds` through the forward and
  tunnel proxy connections down to the inner `HTTPConnection`.
- Implement connect retries for Socks5 connections, mirroring the
  backoff behaviour of `HTTPConnection`.
- Forward the options from both transports. SOCKS proxies support
  `retries` only, now noted in the transports documentation.

See pydantic#1160
@codspeed-hq

codspeed-hq Bot commented Aug 29, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 17 untouched benchmarks
⏩ 7 skipped benchmarks1


Comparing mbeijen:proxy-transport-options (de2e49b) with main (9fdafff)

Open in CodSpeed

Footnotes

  1. 7 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@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 15 files

Re-trigger cubic

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.

1 participant