Description
Description
For a large test suite, running the Selenium Server 4.32.0 in Java coupled with .NET tests which use the Selenium.WebDriver 4.32 nuget package leads to an out of memory exception from Java. After some debugging and troubleshooting I believe I've tracked down the issue to RemoteWebDriver.
To reproduce this I've used Java 24.0.1. The Selenium server is started using this command
java -jar selenium-server-4.32.0.jar standalone --session-timeout 30 --selenium-manager true --max-sessions 4
After the server starts up Java is hovering at 127mb of memory usage:
If I run the test below (see repro code) until failure from Visual Studio which creates and correctly disposes of an instance of RemoteWebDriver, it doesn't take very long for Java to consume all of the memory on the system. Which results in an out of memory exception. Each iteration of the test consumes another few more megabytes.
After a while the memory usage goes over 1GB but doesn't stop increasing there:
The RemoteWebDriver documentation says that all that is required to dispose of an instance is to call the Quit method. I've tried other avenues to dispose of the instance, such as calling Close, Quit and Dispose but nothing makes any difference. I'm starting to wonder if this issue is within the Selenium server itself, somehow not disposing of Chrome instances or connections.
Thanks in advance for any assistance.
Reproducible Code
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Remote;
namespace CodasRegressionTests.Tests.UserManagement.Users;
public class RemoteWebDriverTest
{
[Fact]
public void RemoteWebDriver_CreateAndQuit_LeaksMemory()
{
var chromeOptions = GetChromeOptions();
var remoteWebDriver = new RemoteWebDriver(new Uri("http://localhost:4444/wd/hub"), chromeOptions);
remoteWebDriver.Quit();
}
private ChromeOptions GetChromeOptions()
{
var options = new ChromeOptions
{
};
return options;
}
}