[java] Add close method to JDK 11 client. Ensure close methods for Http client is called. #11345
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Thanks for contributing to Selenium!
A PR well described will help maintainers to quickly review and merge it
Before submitting your PR, please check our contributing guidelines.
Avoid large PRs, help reviewers by making them as simple and short as possible.
Description
Fixes #11270.
Motivation and Context
The memory leak is prominently seen when Augmenter is used which in turn creates a WebSocket connection using the HTTP Client to create a CDP connection. Though webdriver implementation supporting CDP does the same. The same client instance needs to be closed to ensure no resources are being held when the driver quits. The changes add the required code to achieve this.
Additionally, we supply an executor to the JDK 11 Http client for the worker threads, which is shutdown when the client is closed along with the underlying websocket. We also ensure there is no reference to the JDK 11 Http client instance after closing the client. This has helped fix the ever-increasing threads related to the JDK 11 Http client. HttpClientImpl (Java 11's implementation) does a timely check internally to see if no references to the client are there then closes the Selector Manager threads which are later collected when the GC kicks in.
The combination of the above 2 changes has helped ensure that there is no leak from JDK 11 Http client in different scenarios.
Before the changes:
After the changes:
Types of changes
Checklist