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
This commit is contained in:
Arjen Poutsma
2024-04-05 11:41:40 +02:00
parent 7a666cfd86
commit b24221754a

View File

@@ -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) {
}
}
}