Skip to content
This repository was archived by the owner on Jan 20, 2026. It is now read-only.

Fix HTTP connection leak on Datastore errors#186

Merged
eddavisson merged 1 commit intogoogleapis:masterfrom
cmaan:master
Oct 30, 2017
Merged

Fix HTTP connection leak on Datastore errors#186
eddavisson merged 1 commit intogoogleapis:masterfrom
cmaan:master

Conversation

@cmaan
Copy link
Copy Markdown
Contributor

@cmaan cmaan commented Oct 25, 2017

Properly close HTTP response input stream on Datastore errors (fixes #185)

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Oct 25, 2017
Copy link
Copy Markdown
Contributor

@eddavisson eddavisson left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

content.close();
} catch(IOException e) {
logger.fine(String.format("closing content stream failed: %s",e));
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we can also fail to close the stream in the try block that starts at line 231. What about instead adding a try-finally around the code at line 185. That should ensure the stream is closed no matter what happens in this method.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I updated the pull request based on your suggestion, and also modified the IOUtils.copy line to avoid a potential double-close.

Copy link
Copy Markdown
Contributor

@eddavisson eddavisson left a comment

Choose a reason for hiding this comment

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

Looks good, just one nit.

throw makeException(url, methodName, httpResponse.getContent(),
httpResponse.getContentType(), httpResponse.getContentCharset(), null,
httpResponse.getStatusCode());
try(InputStream content = httpResponse.getContent()) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Add a blank space after try.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done!

@eddavisson eddavisson merged commit 61879d1 into googleapis:master Oct 30, 2017
@wsh
Copy link
Copy Markdown
Contributor

wsh commented Nov 3, 2017

@danieln100 we hear you. We've released v1.5.1, which includes this fix. Give it a spin and let us know!

@danieln100
Copy link
Copy Markdown

@wsh Awesome thanks. I deleted my question before you answered me because I wanted to move it to a separate issue but just for context I asked how would I able to use this change since we are experiencing consistent spikes in latency and we think its due to a http connection leak.

What is the best way to use this with the Google Cloud Java Client for Datastore, I am using version 1.8 and looking at the pom.xml file for that version it looks like they are still using 1.3.0. Would just adding this project as a dependency to my project after the dependency for the java client work (I am using SBT)?

Thanks again

@wsh
Copy link
Copy Markdown
Contributor

wsh commented Nov 14, 2017

@danieln100 google-cloud-java/google-cloud-datastore 1.8.0 uses version 1.4.1 of this library. (Seems like you're looking at the proto dependencies.) At least in theory, specifying 1.5.1 might work but, now that this pull request has been merged, 1.5.1 will also be included in the next release of google-cloud-java. Your call. 😄

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

cla: yes This human has signed the Contributor License Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RemoteRpc leaks HTTP connections when handling Datastore errors

5 participants