Ensure that connections are closed for error responses#346
Ensure that connections are closed for error responses#346kohsuke merged 1 commit intohub4j:masterfrom
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! |
oleg-nenashev
left a comment
There was a problem hiding this comment.
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.
Maybe it;s a leftover from the previous fix. closeQuietlydoes not throw IOExceptions
There was a problem hiding this comment.
uc.getInputStream() does
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
|
🐝 |
|
@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