I know AsyncRestTemplate is deprecated, but by looking at the code of HttpComponentsAsyncClientHttpResponse:
@Override
public InputStream getBody() throws IOException {
HttpEntity entity = this.httpResponse.getEntity();
return (entity != null ? entity.getContent() : StreamUtils.emptyInput());
}
@Override
public void close() {
// HTTP responses returned by async HTTP client are not bound to an
// active connection and do not have to deallocate any resources...
}
I see that the InputStream of the apache httpResponse is exposed as the inputStream of the ClientHttpResponse.
Apache HttpComponents's HttpEntity expects this inputStream to be closed by the consumer, but this expectation doesn't seem to match the contract of, for example, ResponseErrorHandler, implementations of which could handle errors without dealing with the content of the response. The close()
of the ClientHttpResponses would do nothing and the underlying httpEntity would be "unconsumed". (Other implementations like OkHttp or Netty do actually close the internal resources)
I am not reproducing this as a specific bug, i'm investigating another issue and found this worth recording just in case something is not correct.
Comment From: rstoyanchev
This appears to be very old standing behavior 296e2189a2376745414a065e9239b066c31e2bed and the comment there left by the main developer on Apache HttpComponents client indicates the close
method is a no-op on purpose. Unless you're actually observing a leak, I'm not sure this needs any further changes.
Comment From: flozano
I'm not observing any leak on my side, the comment just looked scary, contradicting apache docs.
After looking at how apache httpcomponents async client behaves internally the way the HttpComponentsAsyncClientHttpRequestFactory uses it, I think it's safe. Sorry and feel free to discard.