Description
Juan Antonio Farré Basurte opened SPR-8123 and commented
I've noticed that SimpleClientHttpResponse.close() (which it is documented you MUST always call it after completing the request) invokes HttpURLConnection.disconnect() for the wrapped connection.
JDK javadoc for HttpURLConnection states the following:
Calling the close() methods on the InputStream or OutputStream of an HttpURLConnection after a request may free network resources associated with this instance but has no effect on any shared persistent connection. Calling the disconnect() method may close the underlying socket if a persistent connection is otherwise idle at that time.
So, when you close SimpleClientHttpResponse you may be disconnecting the underlying socket for a connection that could otherwise be reused (not the HttpURLConnection instance itself, but the underlying socket connection).
I believe close should close any open InputStreams (if either HttpURLConnection.getErrorStream() or URLConnection.getInputStream() were invoked), but not invoke the disconnect method.
If such functionality is required to be available for users of SimpleHttpUrlConnection, then I believe a new method should be added (for example disconnect()) that is not required to be called.
Thanks,
Juan
Affects: 3.0.5
Issue Links:
- HTTP persistent connections for HTTP Invoker and RestTemplate [SPR-14040] #18612 HTTP persistent connections for HTTP Invoker and RestTemplate ("duplicates")
- SimpleClientHttpResponse.close() does not call close() on URLConnection.getInputStream() if SimpleClientHttpResponse.getBody() was not called before [SPR-17181] #21717 SimpleClientHttpResponse.close() does not call close() on URLConnection.getInputStream() if SimpleClientHttpResponse.getBody() was not called before