Skip to content

Use shared httpx.Client in HTTPXTransport for connection pooling#2935

Merged
adamtheturtle merged 2 commits intomainfrom
adamtheturtle/check-conn-pooling
Mar 29, 2026
Merged

Use shared httpx.Client in HTTPXTransport for connection pooling#2935
adamtheturtle merged 2 commits intomainfrom
adamtheturtle/check-conn-pooling

Conversation

@adamtheturtle
Copy link
Copy Markdown
Member

@adamtheturtle adamtheturtle commented Mar 29, 2026

Summary

  • HTTPXTransport was using httpx.request() (module-level function) for every call, creating a new TCP+TLS connection each time with no connection pooling.
  • Now stores a shared httpx.Client instance and calls self._client.request(), matching the pattern already used by AsyncHTTPXTransport.
  • Added close(), __enter__, and __exit__ methods to HTTPXTransport for proper resource management.
  • Added close() to the Transport protocol and RequestsTransport for parity with AsyncTransport.aclose().
  • Added a context manager test for HTTPXTransport.

Test plan

  • Existing HTTPXTransport tests pass
  • New context manager test passes
  • All pre-commit hooks pass

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.


def close(self) -> None:
"""Close the transport and release resources."""
... # pylint: disable=unnecessary-ellipsis
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Protocol's new close() breaks custom transport implementations

Medium Severity

Adding close() to the @runtime_checkable Transport protocol is a breaking change. Since beartype enforces the protocol at runtime via isinstance checks, any existing user-defined transport that only implements __call__ will now fail validation when passed to VWS, CloudRecoService, or VuMarkService. The close() method needs to exist on every Transport implementation, but external consumers have no way of knowing this without a version bump or deprecation notice.

Fix in Cursor Fix in Web

@adamtheturtle adamtheturtle merged commit aa13fad into main Mar 29, 2026
16 checks passed
@adamtheturtle adamtheturtle deleted the adamtheturtle/check-conn-pooling branch March 29, 2026 07:33
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