From b24221754aa80037df9bcec8194b7ab601c6cb71 Mon Sep 17 00:00:00 2001 From: Arjen Poutsma Date: Fri, 5 Apr 2024 11:41:40 +0200 Subject: [PATCH] ReactorNettyClientResponse should close response body This commit ensures that the response body is drained and closed when the response itself is closed, instead of disposing the connection, as this will disable the connection pool. Closes gh-32528 --- .../http/client/ReactorNettyClientResponse.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/spring-web/src/main/java/org/springframework/http/client/ReactorNettyClientResponse.java b/spring-web/src/main/java/org/springframework/http/client/ReactorNettyClientResponse.java index 44dd4f92a97..2ff4be07ab0 100644 --- a/spring-web/src/main/java/org/springframework/http/client/ReactorNettyClientResponse.java +++ b/spring-web/src/main/java/org/springframework/http/client/ReactorNettyClientResponse.java @@ -27,6 +27,7 @@ import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatusCode; import org.springframework.http.support.Netty4HeadersAdapter; import org.springframework.lang.Nullable; +import org.springframework.util.StreamUtils; /** * {@link ClientHttpResponse} implementation for the Reactor-Netty HTTP client. @@ -89,7 +90,13 @@ final class ReactorNettyClientResponse implements ClientHttpResponse { @Override public void close() { - this.connection.dispose(); + try{ + InputStream body = getBody(); + StreamUtils.drain(body); + body.close(); + } + catch (IOException ignored) { + } } }