#57020·quarkus

REST Client connection leaks when a resource returns a streamed REST Client `Response` and the caller disconnects (regression since 3.31)

Author: michalsomoraCreated Sep 29, 2026Updated Oct 1, 2026
Labelskind/bugarea/rest-client

Describe the bug

Since Quarkus 3.31.0, a blocking Quarkus REST resource that returns the Response of a blocking REST Client call leaks the pooled HTTP client connection if its own caller disconnects before the upstream service answers:

java
@GET
@Path("/pass-through")
public Response passThrough() {
    return Response.fromResponse(upstreamClient.items()).build(); // same with: return upstreamClient.items();
}

Each such abandoned call keeps one connection of the REST client pool checked out forever. Once connection-pool-size connections have leaked, every further call of that client fails with The timeout of ... ms has been exceeded when getting a connection to .... Only a restart helps.

We hit this in production after upgrading from 3.27.1 to 3.33.2: a BFF forwarding a large upstream list lost all 50 connections of the pool within a few hours (mobile clients timing out/leaving the screen while the upstream was slow).

I think this comes from #50990 (Discard remaining REST handlers when the client connection is closed prematurely):

  1. A blocking REST Client method returning jakarta.ws.rs.core.Response does not buffer the body. The entity is an InputStream that reads from the pooled connection, and the connection is released only when that stream is fully read or closed.
  2. Before 3.31, the server response writer (InputStreamMessageBodyHandler.writeTo) always ran, even with the caller gone. It does transferTo + close() on the entity, which released the connection.
  3. Since 3.31, the close handler skips the remaining (cancellable) handlers, including the response writer. Nobody reads or closes the returned entity.
  4. The Vert.x HTTP client stops reading when its buffer is full (back-pressure), so the upstream response never completes, and the connection is never returned or evicted.

This only happens when the upstream body is larger than what can be received without anybody reading it: ~64 KiB buffered by the client plus whatever the TCP socket buffers hold (on loopback the reproducer did not leak with 96 KiB and leaked from 112 KiB on). Smaller bodies are fully received, so the connection is freed anyway.

The change in #55169 (3.38.2) does not fix this. The reproducer still fails on 3.39.5 and 3.40.0.CR1.

Expected behavior

The REST Client connection is returned to the pool when the server-side request is aborted, like in 3.30 and earlier. For example, a Closeable entity (or a REST Client Response) that was never written could be closed when the remaining handlers are discarded.

Actual behavior

The connection stays checked out forever. After connection-pool-size abandoned calls:

jakarta.ws.rs.ProcessingException: The timeout of 5000 ms has been exceeded when getting a connection to localhost:8081
    at org.jboss.resteasy.reactive.client.impl.InvocationBuilderImpl.unwrap(InvocationBuilderImpl.java:212)
    ...
    at org.acme.ProxyResource.direct(ProxyResource.java:45)
Caused by: io.vertx.core.impl.NoStackTraceTimeoutException: The timeout of 5000 ms has been exceeded when getting a connection to localhost:8081

How to Reproduce?

Reproducer: https://github.com/michalsomora/quarkus-rest-client-response-leak-reproducer

bash
./mvnw clean test                                     # 3.39.5: 2 of 3 tests fail
./mvnw clean test -Dquarkus.platform.version=3.30.8   # all pass

The app calls itself: /proxy/* uses a REST Client (connection-pool-size=2) to call /upstream/items, which answers after 2 s with a 1 MiB body. The test opens 2 raw sockets to /proxy/{scenario} and closes them after 500 ms. It waits for the upstream to answer, then expects a third call to return 200.

Endpoint Implementation ≤ 3.30 ≥ 3.31
/proxy/pass-through Response.fromResponse(client.items()).build() OK leaks
/proxy/direct return client.items() OK leaks
/proxy/buffered r.bufferEntity(); return Response.fromResponse(r).build() OK OK

Tested: 3.27.1 and 3.30.8 pass, while 3.31.1, 3.33.2, 3.39.5 and 3.40.0.CR1 fail.

Manual steps:

bash
./mvnw quarkus:dev
curl -m 0.5 localhost:8080/proxy/pass-through; curl -m 0.5 localhost:8080/proxy/pass-through
sleep 3
curl -i localhost:8080/proxy/pass-through   # HTTP 500 after 5 s, and every further call too

Output of uname -a or ver

Linux 6.6.114.1-microsoft-standard-WSL2 x86_64 GNU/Linux

Output of java -version

openjdk version "21.0.10" 2026-01-20 (production: Java 17)

Quarkus version or git rev

3.31.1 – 3.40.0.CR1 (production: 3.33.2), last working 3.30.8

Build tool (ie. output of mvnw --version or gradlew --version)

Apache Maven 3.9.9

Additional information

Workaround: call response.bufferEntity() (or read and close the entity) before returning it from the resource method. The connection is then released independently of the caller.

#50990 is labelled release/breaking-change because handlers such as response filters may no longer run, but it is not mentioned in the 3.31 migration guide. Its side effect on streamed entities also isn't documented. A resource that forwards a REST Client Response is a common proxy/BFF pattern, and here the result is a silent resource leak.