[🐛 Bug]: Containers high memory usage even when no sessions are active
What happened?
I have created a Grid 4 with docker containers in distributed mode and after executing the tests (parallel tests) the memory usage of the containers remains high. The first test execution with 20 parallel threads has successful build and test results but after 3 or more test executions they start failing.

Command used to start Selenium Grid with Docker
https://gist.github.com/Naim995/60d030a7e79bcf1c5f1a3fd19eaf015f
CHROME_NODE_VERSION="108.0"
FIREFOX_NODE_VERSION="108.0"
EDGE_NODE_VERSION="latest"
GRID_VERSION="4.8.0"
NODE_SESSION_TIMEOUT=120
Relevant log output
After multiple test runs I start getting websocket issues
Operating System
Virtual linux machine
Docker Selenium version (tag)
4.8.0
Can you share the commands used and the machine specs so we get an idea. Also, please share the tests you are using to get that memory usage.
Machine specs:
- CPU(s): 32
- CPU MHz: 1995.283
- Thread(s) per core: 1
- Core(s) per socket: 1
- Socket(s): 32
- Swap: 2 GB
- Mem: 32 GB
Everything was working fine in selenium-java 3 version and grid 3. The issue is present only in grid version 4 (distributed mode), so I don't believe the tests or the code has any faults (the only change I did was refactor the repo to selenium-java 4.8). As discussed in the slack channel i'm trying to fork the repository and give you access but its taking longer than expected...
In the mean time here are some additional information: In the pictures you are seeing 3 terminal tabs:
- memory usage of the virtual machine (command: free -g )
- docker stats on the right top corner
- processes inside one of the chrome-nodes
Statistics for GRID 4 with docker, with fresh and clean restart

Statistics for GRID 4 with docker, while tests are running (84 tests, parallel-threads=17)

Statistics for GRID 4 with docker, after tests are finished and no more active sessions
@diemol after 3 time running the test suite the memory usage kep increasing as you can see in the screenshot it was 0.6 now after the third run it is 2.3%

p.s. im still working on providing the repository
@diemol I gave you access as discussed to a private repository to run the same tests that produces this issue. Don't forget to change the grid url to yours. (name of the repor: repo_tests) To execute the tests use the command mentioned in the readme file
Sorry, seems I let this one pass and the invitation expired. Can you please send it again?
@diemol done, please check again
I do not have a machine with those specs, I am using a GitPod instance with 62GB RAM and 16 CPU. So I reduced the number of Nodes to 14.
I am running tests for now, but I am only able to monitor memory and CPU. Tests output is extremely verbose and the code has a lot of internal logic. I appreciate the effort to share the code, but I believe I won't be able to correlate a failure to the code itself.
You mentioned:
Everything was working fine in selenium-java 3 version and grid 3.
And
After multiple test runs I start getting websocket issues
Are you using any of the CDP/DevTools features in your tests? They send back and forth much more data through WebSockets.
I also see your tests have a retry mechanism, which seems to be trying to connect to sessions that are already finished.
Some tests running for quite a long time, it is not so easy to debug and see if there is an issue with Grid

I see memory usage being stable so far, between 29 and 34 GB.
I will retry to replicate the issue without retry mechanism. Nonetheless, the issue is not during test run. The issue is that after all sessions end(you can also leave them hanging they will be killed by sessions timeout) the memory usage of the docker containers are not as in the starting phase (allthough there are no active sessions). Even if the tests take too long or lets say that there are sessions hanging they will timeout and the grid will be cleared of sessions but now memory usage is a bit higher than before the first test run (if that makes sense). So the issue is that after each test run the memory usage of each container keeps increasing (when no sessions active).
But if a test hangs or the session ends in an error because and not closed by the client, memory will stay up because processes on the Grid are still running (browser open, browser driver running as well, etc...). Grid tries to clean up as much as possible, but it cannot kill processes left from a session that ended in errors. That is why we recommend to have disposable Grids.
And even if everything is closed, it takes a moment until the garbage collection happens and memory is released.
Personally I think the timeout logic should take care of clearing/killing processes after a certain time. If I remember correctly my memory usages was increasing even when all of the tests were successful so I think the issue lies somewhere else. Anyways I will implement the recommended logic of using disposable grids and close the issue for now
Thank you for the time!
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.