Skip to content

SimpleClientHttpResponse disconnects the underlying HttpURLConnection when closing [SPR-8123] #12775

Closed
@spring-projects-issues

Description

@spring-projects-issues

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:

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)status: duplicateA duplicate of another issue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions