Repository navigation
fix(binding-http): client connection reuse per origin/authority + per-connection exchange/queue scope - #1812
Merged
Conversation
…e headers A response arriving on a kept-alive HTTP/1.1 connection after its exchange was torn down (e.g. the application reset the response) left client.exchange null; onDecodeHttp11Headers then dereferenced it, throwing inside the worker (AgentTerminationException) and crash-looping the engine. HTTP/2 already tolerates a frame for an unknown stream. Guard the HTTP/1.1 response-headers decode the same way: when there is no exchange to receive the response, the connection is desynchronized, so ignore the remainder and clean up the network. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> (cherry picked from commit 7b5a863)
HttpClientPool is keyed only by resolvedId, and supplyClient() selected a reusable connection by HTTP version and idle/reply state without matching the request :authority. When one http client binding fans out to multiple authorities (e.g. the MCP proxy routing several south mcp clients through a shared sys:http_client), an idle connection established to authority A could be reused to send a request for authority B, so B's request was answered by A. Track the connected authority on HttpClient and require it to match in supplyClient(); create a new connection per authority otherwise. Adds a failing-first IT (requests.different.authorities) driving two sequential requests with distinct authorities through one client binding and asserting two distinct upstream connections. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> (cherry picked from commit 43750d8)
…ction The per-authority connection reuse fix (43750d8) made supplyClient() filter by :authority, so one HttpClientPool (keyed only by resolvedId) now hosts several HttpClient connections for different authorities. The pool, however, kept a single exchanges map and a single request queue (httpQueueSlot/flushNext/availableSlotSize), both keyed by streamId — yet streamId comes from HttpClient.nextStreamId() (maxClientStreamId), which is per-connection and restarts at 1 for every client. Two concurrent requests to different authorities therefore both allocate streamId 1: the later exchanges.put() evicts the earlier exchange, and the pool-wide flushNext() resolves a queued request via exchanges.get(streamId) to the wrong (clobbered) exchange, so one request stalls indefinitely. This surfaced as a hang when the MCP proxy hydrated tools/prompts/resources across three upstream authorities through one shared sys:http_client. Move the exchanges map and the request queue down onto HttpClient so they are scoped per connection, matching the per-connection streamId space. Adds a failing-first IT (concurrent.requests.different.authorities) driving two concurrent requests with distinct authorities through one client binding, with the server holding both requests open before responding; it times out against the previous code and passes with the fix. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> (cherry picked from commit 71d754a)
…ent authorities Adds an HTTP/2 counterpart to the rfc7230 concurrent.requests.different.authorities regression: two concurrent requests to distinct authorities each open their own h2 connection in one shared pool, the server holds both requests open (cross-await) before responding, and both responses arrive on wire stream id 1. Before the per-connection exchanges/queue fix this collides in the pool-wide map (both connections' stream 1 alias the same entry) and times out; with the fix each connection owns its stream-id space and both exchanges complete. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> (cherry picked from commit d9964d2)
…Serve seam Connection reuse eligibility was an inline exact match on :authority (host:port) only, with :scheme ignored. Capture :scheme alongside :authority and route the selection in supplyClient() through a canServe(scheme, authority) predicate on HttpClient, so reuse is keyed by origin (scheme + host + port) per RFC 6454. canServe also carries a serviceableNames set (empty for now) as the seam for HTTP/2 connection coalescing: a request may later reuse an h2 connection whose TLS certificate covers the requested name, even when the authority differs. Populating serviceableNames from certificate SANs surfaced by the tls binding, and refining the match to host-vs-SAN, is a purely additive follow-on; HTTP/1.1 never consults SANs. Today both branches reduce to an exact origin match, so behaviour is unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> (cherry picked from commit 5d6d506)
…connections supplyClient() reused a still-connecting connection for any further request to the same origin (the !replyOpened clause), so two concurrent requests to one authority piled onto a single HTTP/1.1 connection and the second stalled behind the first instead of opening a second connection. Make connection selection tiered: (1) prefer a connection ready to take the request now — an HTTP/2 connection (multiplexes), a connecting connection on an h2-capable pool (will multiplex), or an idle HTTP/1.1 connection with nothing queued; (2) otherwise open a new connection while under maximum.connections; (3) only when at the limit, fall back to the previous reuse semantics and queue behind a busy connection. HTTP/2 multiplexing, h2c, idle reuse, and at-limit queueing (pool size 1) are all unchanged; only concurrent same-origin HTTP/1.1 requests under available capacity now fan out across connections. Adds a failing-first IT (concurrent.requests.same.authority): two concurrent requests to one authority with the server holding both open before responding; it times out against the previous code and passes once the requests distribute. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> (cherry picked from commit cc3a740)
This was referenced Jun 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
General
binding-httpclient connection-management fixes, extracted from theexamples/mcp.proxybranch (#1793) so they can land ondevelopindependently. Thedefect surfaced via the MCP proxy's shared
sys:http_clientfanning out to multipleupstream authorities, but it is general to
binding-http: any singlehttpclient bindingthat routes to more than one
:authorityis affected.Fixes #1811.
Changes
:authorityvia acanServecoalescing seam onHttpClient(previouslysupplyClient()reused any idle connection by HTTP version + idlestate only, never matching
:authority, so a request could be sent over a connection to adifferent host).
exchanges+ the request queue per connection (moved fromHttpClientPooldowninto
HttpClient). Stream ids are per-connection (1, 3, 5 …), so the pool-wide map/queuecollided across concurrent authorities and stalled a request.
supplyClient:prefer-ready / new-under-limit / at-limit-fallback).
Testing
./mvnw verify -pl runtime/binding-http—rfc7230/rfc7540client + serverconnection-management ITs green, including new regression scenarios:
requests.different.authorities— sequential requests to two authorities through oneclient binding must open two connections (old: response2 never arrives).
concurrent.requests.different.authorities— two concurrent cross-authority exchangescoexist (old:
TestTimedOut; new: passes).concurrent.requests.same.authority— concurrent same-origin requests distributed.🤖 Generated with Claude Code