Skip to content

Reuse pooled HTTP connections for workspace calls - #1795

Draft
JTSIV1 wants to merge 7 commits into
mainfrom
jtsiv1/ug-pooled-http
Draft

JTSIV1 wants to merge 7 commits into
mainfrom
jtsiv1/ug-pooled-http

Conversation

@JTSIV1

@JTSIV1 JTSIV1 commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

What

  • Workspace HTTP calls now go through one pooled httpx.Client per process instead of a new urllib connection per request. _http_open returns a urllib-compatible response, so callers keep the same headers, timeouts, retries and error strings.
  • The client is created lazily, replaced after fork, rejects cookies, and follows redirects like urllib. One difference: it drops Authorization on cross-origin redirects, where urllib re-sent it.
  • macOS system proxies (getproxies(), proxy_bypass) are honored, including scheme-less host:port values.
  • The host-type probe (/.well-known/databricks-config) uses the same pool. mcp_oauth, mcp_web_search and the routing hook stay on urlopen since they run after handoff.
  • httpx errors map to urllib's HTTPError / URLError shapes, so retry routing is unchanged.
  • The client's SSL context is built after tls.apply() (Fix SSL cert verification failures behind enterprise inspection proxies #168), so it verifies against the same trust store urllib did (os by default, or python), and Fix SSL cert verification failures behind enterprise inspection proxies #168's certificate-failure hint still shows.

Why

A new HTTPS connection to the workspace costs about 4 round trips: 0.035 s from us-west-2, 0.255 s from us-east-1, 0.94 s from ap-south-1. A reused one costs about 1. ug configure and ug claude each make several workspace calls, and every one of them paid the full handshake.

UG's lookups (probe, discovery, catalog), median of 8 runs:

region before after
Mumbai (ap-south-1) 2.73 s 2.09 s
us-east-1 1.05 s 0.88 s
Oregon (us-west-2) 0.41 s 0.46 s (noise)

TCP connects per run: 12 → 8.

Testing

  • New unit tests: header/timeout passthrough, cookie rejection, proxy selection and bypass, scheme-less proxies, fork reset, redirect and transport error mapping, host-type probe on the pooled transport.
  • Fix SSL cert verification failures behind enterprise inspection proxies #168's TLS suites (test_tls.py, test_tls_https.py, which run every client against a local HTTPS server under both trust stores) pass on the pooled transport. A new test checks the SSL context is built after tls.apply().
  • Full unit suite in a clean env: same failures as base, node for node.

This pull request and its description were written by Isaac.

JTSIV1 and others added 6 commits November 20, 2026 12:38
Co-authored-by: Isaac <no-reply@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>
Map httpx's redirect-exceeded error to a urllib HTTPError with a
status-shaped reason, and other transport errors to URLError, so callers
see what urllib would have raised. Normalize scheme-less macOS system
proxies to http:// URLs as urllib's proxy handler does. Route the
unauthenticated workspace host-type probe through the pooled client.

Co-authored-by: Isaac <no-reply@databricks.com>
The host-type probe rides the pooled client now, so patch _http_open
instead of urlopen; error-shape expectations are unchanged.

Co-authored-by: Isaac <no-reply@databricks.com>
tls.apply() runs before the pooled client's SSL context is built, so it
verifies against the same trust store (UG_TLS_TRUST_STORE, state.json,
default os) as the urllib path did, keeping the inspection-proxy fix.
A test pins the ordering and reuses the helper's context.

Co-authored-by: Isaac <no-reply@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>
@JTSIV1
JTSIV1 force-pushed the jtsiv1/ug-pooled-http branch from c4986a7 to c196246 Compare November 20, 2026 14:17
Co-authored-by: Isaac <no-reply@databricks.com>
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