Skip to content

Instantly share code, notes, and snippets.

@hispanic
Created November 26, 2015 12:45
Show Gist options
  • Save hispanic/6df2a1c0e7dce13245f9 to your computer and use it in GitHub Desktop.
Save hispanic/6df2a1c0e7dce13245f9 to your computer and use it in GitHub Desktop.
HttpClient Logging - No leaks
Connection leased: [id: 66][route: {}->http://myhost:8080][total kept alive: 2; route allocated: 3 of 50; total allocated: 5 of 100]
Connection leased: [id: 64][route: {}->http://myhost:8080][total kept alive: 4; route allocated: 3 of 50; total allocated: 5 of 100]
Connection leased: [id: 64][route: {}->http://myhost:8080][total kept alive: 4; route allocated: 3 of 50; total allocated: 5 of 100]
Connection leased: [id: 64][route: {}->http://myhost:8080][total kept alive: 4; route allocated: 3 of 50; total allocated: 5 of 100]
Connection leased: [id: 64][route: {}->http://myhost:8080][total kept alive: 4; route allocated: 3 of 50; total allocated: 5 of 100]
Connection leased: [id: 67][route: {}->http://myhost:8080][total kept alive: 3; route allocated: 3 of 50; total allocated: 5 of 100]
http-outgoing-64: Shutdown connection
Connection leased: [id: 67][route: {}->http://myhost:8080][total kept alive: 3; route allocated: 2 of 50; total allocated: 4 of 100]
Connection leased: [id: 66][route: {}->http://myhost:8080][total kept alive: 2; route allocated: 2 of 50; total allocated: 4 of 100]
http-outgoing-66: Shutdown connection
Connection leased: [id: 67][route: {}->http://myhost:8080][total kept alive: 2; route allocated: 1 of 50; total allocated: 3 of 100]
Connection leased: [id: 67][route: {}->http://myhost:8080][total kept alive: 2; route allocated: 1 of 50; total allocated: 3 of 100]
Connection leased: [id: 68][route: {}->http://myhost:8080][total kept alive: 2; route allocated: 2 of 50; total allocated: 4 of 100]
Connection leased: [id: 67][route: {}->http://myhost:8080][total kept alive: 3; route allocated: 2 of 50; total allocated: 4 of 100]
Connection leased: [id: 68][route: {}->http://myhost:8080][total kept alive: 2; route allocated: 2 of 50; total allocated: 4 of 100]
http-outgoing-68: Shutdown connection
Connection leased: [id: 69][route: {}->http://myhost:8080][total kept alive: 2; route allocated: 2 of 50; total allocated: 4 of 100]
http-outgoing-67: Shutdown connection
Connection leased: [id: 70][route: {}->http://myhost:8080][total kept alive: 2; route allocated: 2 of 50; total allocated: 4 of 100]
@hispanic
Copy link
Author

In this sequence, connections #64, #66, and #67 are in-use. Connection #64 is then shut-down by HttpClient. The route allocations decrement, as expected. Notice that the connection with this ID no longer appears in the log. Connection #66 is then shut-down, with the route allocations decrementing again. A couple requests later, a new connection (allocation) is established (#68). The route allocations increment. This connection #68 only ends up being used for two requests before being discarded by HttpClient. The rest of the lines show two new connections being created and a third being discarded.

For more information, please see How to Read HttpClient Logging and Prevent Connection Leaks.

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