sharedProviderHttpClient function
The shared keep-alive HTTP client for provider streams.
Streaming adapters use it when the caller injects no client: a fresh
http.Client per request churns a new TCP+TLS connection every turn,
which on tool-heavy runs piles up TIME_WAIT sockets until connect()
stalls into the watchdog (kimi-cli/pi reuse one client for exactly this
reason). The shared client is never closed per call — an aborted stream
closes only its own response subscription.
If providerHttpClientFactory is set, its product is used and cached
instead of the default http.Client.
Issue #1392 (bench round 3): with FA_CONN_DEBUG=1 (or
FA_PROVIDER_DEBUG) the inner product is the bench-traced client —
every send/first-byte/watchdog event lands as a structured FA_CONN
line on stderr (and FA_CONN_TRACE_FILE), so a bench stall is
diagnosable from the live run log. Without the flag the chain is
byte-for-byte what it was.
Implementation
http.Client sharedProviderHttpClient() {
connTrace.configureFromEnv();
return _sharedProviderClient ??=
// gh-1395: the wrapper is a pass-through recorder with FA_CONN_DEBUG
// off (E4: identical response objects); with the knob on it adds the
// conn-open/first-byte trace lines (AC2). The pool semantics are
// unchanged — the bench trace rides the same seam as the innermost
// product.
connTraceWrapProviderClient(
providerHttpClientFactory?.call() ??
connTrace.tracedClient() ??
http.Client(),
canInstallObserver: providerHttpClientFactory == null,
);
}