-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[🐛 Bug]: Memory leak running hub, due to HttpClient-x-SelectorManager threads never closed #13246
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
Comments
@bhecquet, thank you for creating this issue. We will troubleshoot it as soon as we can. Info for maintainersTriage this issue by using labels.
If information is missing, add a helpful comment and then
If the issue is a question, add the
If the issue is valid but there is no time to troubleshoot it, consider adding the
If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C),
add the applicable
After troubleshooting the issue, please add the Thank you! |
@pujagani didn't you troubleshoot this already in another issue? |
I just have pushed a commit cdbe9c6 that might point into the direction why there are idling websocket. There was a misunderstanding in what cases the |
We've analyzed the code in JdkHttpClient.java and the memory dump and we thought the problem might also be in the close method, where "websockets" list is not cleared, which could lead to references being kept |
The other issue was also related to a leak but that was pertaining to a leak happening in only a particular Java version. I have handled a similar one via #11345 earlier. But I think @joerg1985 has an idea for this one. If not, I am happy to take a look. |
@bhecquet the reference to the HttpClient should be dropped after some time, so this list should not be an issue. |
Hello, I just tested the 4.16.0 version, and I observe the same behaviour as with 4.15.0 |
Okay one thing that should be checked, we have chain like this:
Now the Driver does raise an error on the Websocket
I don't think the other connections are also disconnected in this case.
@pujagani would you like to check this or should i give it a try at a undefined point in the future? |
I can check this in a day or two. I am happy to help, though you are the expert in this area. I might ask questions as and when I need the guidance. |
I was able to reproduce the issue with Java 11 at a small scale but what I see is leftover SelectorManager threads. I am looking into triaging it further. The same does not occur with Java 21 since HttpClient implements AutoCloseable. |
I am not able to run into the error in the above example. This issue does not mention leak due to errors, though I partially understand the thought process regarding it being related to CDP, but I don't fully understand your concern here. Can you help me understand please? |
@bhecquet Can you help share the tests that you run or the nature of the tests? Do you run a lot of CDP or BiDi tests? I would appreciate a reproducible code script to triage this further. |
Hello @pujagani , I will try to provide you a minimal test that reproduce the problem |
Running the code of #13316 in a loop does leak threads for me and also log's warnings:
|
Thank you! But that is an error situation which involves enabling BiDi and using CDP. I agree that needs to be solved too. But I understand the issue here is mainly that threads are leaking when tests are running without any errors or I will know better once the example is shared. |
I've a strange behavior when trying to reproduce the thread leak problem on my setup. Moreover, I notice (it may be expected behaviour), that thread created when augmenting driver may wait 5 to terminate, after test ends |
This should be the one for the |
Hello, I managed to reproduce the problem with limited setup:
The key point seems to be the EventFiringDecorator I don't know if it's related but, on the node, when session stop, I get the following message:
|
@bhecquet Thank you so much. This is what I was looking for. Let me try and reproduce it and take it from there. I am going to slim down the example further to identify the pain point. |
"With it, threads remain for very long time (> 30 mins), and without, they are stopped after up to 11 mins (which in my opinion is still quite long 😄 )" @bhecquet Can you help me understand this? Which threads are these? On the client side or hub side? |
I can reproduce the leak and I now see the pattern mentioned above. Thank you for sharing the details. |
@bhecquet Can you try the above suggestion and see if that helps? |
@pujagani : thanks for the tip, it seems to work around the problem but I won't be able to test at scale in the next days (it's holiday time now 😋 ) |
No rush, I understand. Please update here whenever you get a chance. |
@pujagani do we need to figure this out, regardless? Would it make sense just not to allow passing in a decorated driver to the augmenter? |
Hello @titusfortner, But it's only an opinion 😃 |
"if we augment the driver first and then use the decorator then the leak does not happen", I think the combination of Augmenter and decorator might be preventing some calls to close method. We might not have to do anything here but mainly I need to find a logical reason to recommend to augment first and then decorate. |
I have revisited it, and there is absolutely no problem in handling the threads. The case that does not work (reason in comments):
The case that works (reason in comments):
I am trying to see if I can fix this in a meaningful manner else might have to go with Titus's suggestion. |
I think the best option is to not allow passing in decorated drivers to the Augmenter.
I have added a warning for this currently since not allowing that immediately might cause breaking changes for the users. @bhecquet I would recommend updating your codebase to decorate an augmented driver. Since that is the long term plan. Note: This will not be a problem when we move to BiDi completely and port all commands to it. The Java porting POC for BiDi demonstrates that Augmenter will not be needed. |
Thanks a lot @pujagani for the analysis Regards |
Hi, Does this issue is fixed on last official release? We use 4.15.0 and we have the issue on node on different machines .. They are unplugged on the grid after some hours with this message : java.io.IOException: Too many open files |
Hi @pujagani, |
@IlyaUk Hey! So the issue reported here was reproduced under the circumstance of using Decorator and Augmenter together. The leak was not reproduced as expected so there was no fix that went in. Can you create another issue with the exact problem you are facing with details of how we can reproduce it? I can help take a look if I can reproduce it. |
This issue was closed because we did not receive any additional information after 14 days. |
This issue has been automatically locked since there has not been any recent activity since it was closed. Please open a new issue for related bugs. |
What happened?
Hello
On our hub (version 4.15.0, JDK 11.0.20), running 13 nodes, memory increase continuously as tests run. Attaching a VisualVM shows that it seems to be caused by an increasing number of HttpClient-x-SelectorManager threads that are not closed (seems similar to #12206 or #11336)
Operations are normal, except when max memory is reached. In this case, hub does not respond anymore

In the graphic above, you can see that 300 more threads have been created in an hour
Is there a way (to help) to track down the creator of the staled threads ? Thread dump doesn't help much
Thanks
How can we reproduce the issue?
Start a hub Start some nodes Execute many tests. I think the more tests are run, the easier it's to point the issue
Relevant log output
Operating System
Windows / Linux
Selenium version
4.11.0
What are the browser(s) and version(s) where you see this issue?
any browser
What are the browser driver(s) and version(s) where you see this issue?
any browser
Are you using Selenium Grid?
4.15.0
The text was updated successfully, but these errors were encountered: