RFR: JDK-8288746: HttpClient resources could be reclaimed more eagerly

Daniel Fuchs dfuchs at openjdk.org
Mon Jun 27 11:16:15 UTC 2022


On Mon, 20 Jun 2022 14:09:27 GMT, Daniel Fuchs <dfuchs at openjdk.org> wrote:

> Hi,
> 
> Please find here a patch that should help the HttpClient's SelectorManager thread to terminate more timely, allowing the resources consumed by the client to be released earlier.
> 
> The idea is to use a Cleaner registered with the HttpClientFacade to wakeup the Selector when the facade is being gc'ed.
> Some tests have been modified to wait for the selector manager thread to shutdown, and some of them have been observed to timeout when the fix is not in place.

If the selector returns a non zero value when being woken up it means that some key is selected, which would imply that some operation is still in progress. So isReferenced() would return false in that case (since it returns true only if both the facade is no longer referenced and the operation count is reduced to 0). 
However with HTTP/2, because connections remain open, we could unfortunately receive some GOAWAY frame from a server at a time where we're trying to shutdown the client, which would then keep it alive for another round. So the assumption that if there is something to read or write an operation is still in progress may not be 100% true. 
Let me think on this.

-------------

PR: https://git.openjdk.org/jdk/pull/9217


More information about the core-libs-dev mailing list