-
Notifications
You must be signed in to change notification settings - Fork 731
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
Ensure that connections are closed for error responses #346
Conversation
- This was endless fun to trace, but I found it at last. This should stop the `WARNING: A connection to https://api.github.com/ was leaked. Did you forget to close a response body?` messages in the logs when using the OkHttpConnector.
No I do not have an automated test for this fix, the testing I have done is to use the old version and run some code that is known to cause the issue... wait maybe 5 minutes (can show as early as immediately, seems to be at worst every 5 minutes) and then you get the error in the logs Then switch to the fix, rerun the same code (GHRepository.getCollaborators() with an anonymous connection is good) and then wait 15 minutes... no error logged! |
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.
Generally looks good to me 🐝 . The code in Requester
is definitely misplaced
// ensure that the connection opened by getResponseCode gets closed | ||
try { | ||
IOUtils.closeQuietly(uc.getInputStream()); | ||
} catch (IOException ignore) { |
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.
Maybe it;s a leftover from the previous fix. closeQuietly
does not throw IOException
s
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.
uc.getInputStream()
does
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.
And when using the OkHttpConnector and the HTTP response code is >= 400 it will throw the IOE always (not that JVM's HttpURLConnection will do that)... given that this is the expected case for returning true
, we need to access the error stream in order to ensure that the request is closed for the OkHttpConnector
path... which we have to do using the error stream 🙄
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.
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.
Also https://github.com/square/okhttp/blob/parent-2.7.5/okhttp-urlconnection/src/main/java/com/squareup/okhttp/internal/huc/HttpURLConnectionImpl.java#L145 which is the only way to close the request body and prevent the warning!
@stepehenc have you tried to run existing ITs? |
@KostyaSha they fail for me before making changes, I do not expect them to magically pass after my changes, but I have done as extensive a testing as possible without the less than stellar automated tests |
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.
ok, let's try
🐝 |
@reviewbybees done, @kohsuke can you merge and release? |
This pull request originates from a CloudBees employee. At CloudBees, we require that all pull requests be reviewed by other CloudBees employees before we seek to have the change accepted. If you want to learn more about our process please see this explanation. |
stop the
WARNING: A connection to https://api.github.com/ was leaked. Did you forget to close a response body?
messages in the logs whenusing the OkHttpConnector.
@reviewbybees