Skip to content
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

Merged
merged 8 commits into from
Jun 13, 2022
Merged

Fix for #1286 #1287

merged 8 commits into from
Jun 13, 2022

Conversation

velo
Copy link
Member

@velo velo commented Oct 15, 2020

When feign is done with the response, also invoke close on http response (if closeable)

#1286

When feign is done with the response, also invoke close on http response (if closeable)
@velo velo added hacktoberfest bug Unexpected or incorrect behavior labels Oct 15, 2020
@@ -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();
Copy link
Contributor

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.

Copy link
Contributor

@austinpio austinpio Oct 28, 2020

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?

Copy link
Member Author

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

Copy link
Contributor

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

@kdavisk6 kdavisk6 added the waiting for feedback Issues waiting for a response from either to the author or other maintainers label Dec 29, 2020
Copy link
Contributor

@austinpio austinpio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requesting changes

@aleks-demin
Copy link

    final HttpEntity entity = httpResponse.getEntity();
    if (entity == null) {
      return null;
    }

apache response won't be closed in case of missing entity.
Is this case should be handled as well?

@velo velo merged commit 1abcc42 into OpenFeign:master Jun 13, 2022
@velo velo deleted the release-socket branch June 13, 2022 23:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Unexpected or incorrect behavior waiting for feedback Issues waiting for a response from either to the author or other maintainers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants