-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix for #1286 #1287
Fix for #1286 #1287
Conversation
When feign is done with the response, also invoke close on http response (if closeable)
@@ -233,6 +231,8 @@ public Reader asReader(Charset charset) throws IOException { | |||
@Override | |||
public void close() throws IOException { | |||
EntityUtils.consume(entity); | |||
if (httpResponse instanceof CloseableHttpResponse) | |||
((CloseableHttpResponse) httpResponse).close(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could this close method call be enclosed in a finally
block? that would ensure the socket is released even in the event of an exception when consuming the entity.
It is also the approach recommended here - https://hc.apache.org/httpcomponents-client-ga/quickstart.html
quoted text from the document
// In order to ensure correct deallocation of system resources
// the user MUST call CloseableHttpResponse#close() from a finally clause.
try{
EntityUtils.consume(entity1);
} finally {
response1.close();
}
- Additionally it would also not show up as a potential issue in static code analyzers like Fortify, which expect to see a finally block which closes the connection.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hi @velo you reckon, this finally block is something we could incorporate in here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point, lemme me do it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would be really great. Thank you @velo
httpclient/src/main/java/feign/httpclient/ApacheHttpClient.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Requesting changes
final HttpEntity entity = httpResponse.getEntity();
if (entity == null) {
return null;
} apache response won't be closed in case of missing entity. |
Co-authored-by: Austin Pio <[email protected]>
* Fix for #1286 When feign is done with the response, also invoke close on http response (if closeable) * Update httpclient/src/main/java/feign/httpclient/ApacheHttpClient.java Co-authored-by: Austin Pio <[email protected]> * Update ApacheHttpClient.java * Use finally block to close http5 client * Use finally block to close http5 client Co-authored-by: Kevin Davis <[email protected]> Co-authored-by: Austin Pio <[email protected]>
* Fix for #1286 When feign is done with the response, also invoke close on http response (if closeable) * Update httpclient/src/main/java/feign/httpclient/ApacheHttpClient.java Co-authored-by: Austin Pio <[email protected]> * Update ApacheHttpClient.java * Use finally block to close http5 client * Use finally block to close http5 client Co-authored-by: Kevin Davis <[email protected]> Co-authored-by: Austin Pio <[email protected]>
When feign is done with the response, also invoke close on http response (if closeable)
#1286