Skip to content

Release the client connection when a request fails before it is sent - #14457

Merged
dstepanov merged 3 commits into
5.2.xfrom
denis/client-release-connection-on-send-failure
Nov 13, 2026
Merged

dstepanov merged 3 commits into
5.2.xfrom
denis/client-release-connection-on-send-failure

Conversation

@dstepanov

@dstepanov dstepanov commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Only a form encoding failure released the pooled connection. Any other
failure while the request was built, e.g. a body no writer can encode, left
the connection taken until its read timeout. A failure while the request is
set up on the connection now fails the exchange and closes the connection.

Tests: ConnectionLeaseReleaseSpec, which fails with a read timeout without the change.

Follow-up commit: the connection is released on its event loop, since the request can be built on the calling thread, and a full request body that was taken but not written is released when a customizer's onRequestPipelineBuilt throws. ConnectionLeaseReleaseSpec now covers a customizer passed to the client builder that fails while the request pipeline is built (without a body, with a full body and with a 100 Continue). A customizer registered with the context cannot reach this path: the composite customizer logs and drops its exceptions.

Only a form encoding failure released the pooled connection. Any other
failure while the request was built, e.g. a body no writer can encode, left
the connection taken until its read timeout. A failure while the request is
set up on the connection now fails the exchange and closes the connection.
@dstepanov dstepanov added the type: bug Something isn't working label Nov 13, 2026
…ritten request body

The request can be built on the calling thread when the connection was ready
before the caller went on, so a failure while it is built released the
connection off the event loop, where the pool is not safe to change. The
release now runs on the connection's event loop.

A failure in a customizer's onRequestPipelineBuilt left a full request body
that was taken from the body but not written yet unreleased, because the
response handler only releases it while it waits for a 100 Continue.
@dstepanov
dstepanov marked this pull request as ready for review November 13, 2026 10:40
…ot fail on its own

The request line and headers are built by buildNettyRequest before
sendRawRequest builds them again through the same builder, so the catch around
the second build never ran. The release of a connection now always goes
through the event loop. The spec covers a customizer that fails while the
request pipeline is built, for a request without a body, with a full body and
with a 100 Continue, and a request whose body fails before its connection is
open.
@sonarqubecloud

Copy link
Copy Markdown

@dstepanov
dstepanov merged commit 282bd17 into 5.2.x Nov 13, 2026
18 checks passed
@dstepanov
dstepanov deleted the denis/client-release-connection-on-send-failure branch November 13, 2026 12:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants