selenium: Chromedriver quit() method doesn't close all chrome.exe processes

OS: Windows 7 (64-bit) Selenium Version: 3.14 Browser: Chrome, Firefox

Browser Version:
Google Chrome 68.0.3440.106 (Official Build) (64-bit)

Expected Behavior -

chromedriver.exe processes to be closed. geckodriver.exe processes to be closed.

Actual Behavior -

Hello guys, since a month ago, we’re expecting some kind of problems trying to kill the chromedriver.exe and geckodriver.exe processes.

We usually run several tests simultaneously and when the TestSuite ends, many chromedriver.exe / geckodriver.exe processes still there on the system.

This problem causes the system goes slower and slower, causing at the end the system crashes.

This is the message we’re receiving from the driver:

Trace init:

Starting ChromeDriver 2.41.578737 (49da6702b16031c40d63e5618de03a32ff6c197e) on port 36461
Only local connections are allowed.
ago 21, 2018 1:59:03 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS

When we try to quit() the driver:

INFO: Unable to drain process streams. Ignoring but the exception being swallowed follows.
org.apache.commons.exec.ExecuteException: The stop timeout of 2000 ms was exceeded (Exit value: -559038737)
	at org.apache.commons.exec.PumpStreamHandler.stopThread(PumpStreamHandler.java:295)
	at org.apache.commons.exec.PumpStreamHandler.stop(PumpStreamHandler.java:181)
	at org.openqa.selenium.os.OsProcess.destroy(OsProcess.java:135)
	at org.openqa.selenium.os.CommandLine.destroy(CommandLine.java:153)
	at org.openqa.selenium.remote.service.DriverService.stop(DriverService.java:223)
	at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:95)
	at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:548)
	at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:605)
	at org.openqa.selenium.remote.RemoteWebDriver.quit(RemoteWebDriver.java:448)
	at utils.Utils.quit(Utils.java:2783)
	at utils.Utils.guardarResultado(Utils.java:2816)
	at com.bbva.ebcf.pon.LimitePonMismoUsuarioFirmando.tearDown(LimitePonMismoUsuarioFirmando.java:163)
	at junit.framework.TestCase.runBare(TestCase.java:140)
	at junit.framework.TestResult$1.protect(TestResult.java:110)
	at junit.framework.TestResult.runProtected(TestResult.java:128)
	at junit.framework.TestResult.run(TestResult.java:113)
	at junit.framework.TestCase.run(TestCase.java:124)
	at junit.framework.TestSuite.runTest(TestSuite.java:243)
	at junit.framework.TestSuite.run(TestSuite.java:238)
	at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

ago 22, 2018 9:31:43 AM org.openqa.selenium.os.OsProcess destroy
SEVERE: Unable to kill process java.lang.ProcessImpl@70eecdc2

This is not happening every single time, for example, if we try to reproduce the error in oir IDE’s it is almost impossible. It seems that is something related whith too many chrome processes running at the same time (My guess).

This is the method we call in every single test we run (in @After ) we close and quit the driver:

	public static void quitDriver(WebDriver driver)
	{

		try
		{

			driver.close();
		}
		catch(Exception e1)
		{
			
		}

		try
		{
			driver.quit();
		}
		catch(Exception e)
		{

		}

	}

And this is the way we start the driver:

	System.setProperty("webdriver.chrome.driver", "lib/chromedriver.exe");

	String downloads = new File("downloads").getAbsolutePath();				
	HashMap<String, Object> chromePrefs = new HashMap<String, Object>();
	chromePrefs.put("profile.default_content_settings.popups", 0);
	chromePrefs.put("download.default_directory", downloads);	
	chromePrefs.put("download.prompt_for_download", false);
	chromePrefs.put("download.directory_upgrade", true);

	ChromeOptions options = new ChromeOptions();
	options.setExperimentalOption("prefs", chromePrefs);
	options.addArguments("enable-automation");
	options.addArguments("start-maximized");
	options.addArguments("disable-popup-blocking");
	options.addArguments("disable-default-apps"); 
	//options.addArguments("--no-sandbox");
	options.addArguments("ignore-certificate-errors");
	
	LoggingPreferences logPrefs = new LoggingPreferences();
	logPrefs.enable(LogType.PERFORMANCE, Level.ALL);
	
	options.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);
	options.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
	
	driver = new ChromeDriver(options);

We have tried almost everything (we are 5 testing engineers working on the same project) and the processes are still there.

image

Windows can’t kill the process with taskkill /f /im chromedriver.exe

image

So… Please, if someone have some idea, we would appreciate it. We have read a lot, before opening this issue.

Thank you guys! Thank you community!

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 24 (2 by maintainers)

Most upvoted comments

https://stackoverflow.com/questions/10752512/get-pid-of-browser-launched-by-selenium/13650111 there is the answer. I have same issue, but i sloved. u can try"ChromeDriverService service = ChromeDriverService.createDefaultService();" before create ChromeDriver,u will find this issue is not exists

In our code we always had “–no-sandbox” COMMENTED OUT and the problem is still there. I’m wondering why no one addresses this issue in the Selenium code; here is a scriplet from org.openqa.selenium.os.OsProcess class; have a look at the comment: `public int destroy() { SeleniumWatchDog watchdog = executeWatchdog; watchdog.waitForProcessStarted();

// I literally have no idea why we don't try and kill the process nicely on Windows. If you do,
// answers on the back of a postcard to SeleniumHQ, please.
if (!thisIsWindows()) {
  watchdog.destroyProcess();
  watchdog.waitForTerminationAfterDestroy(2, SECONDS);
}

if (isRunning()) {
  watchdog.destroyHarder();
  watchdog.waitForTerminationAfterDestroy(1, SECONDS);
}`

Why was this closed?

please submit all ChromeDriver issues to: https://bugs.chromium.org/p/chromedriver/issues/

As far as it hits three drivers (IEDriverServer, chromedriver and geckodriver) developed independently by different people, and taking into account the fact that we did not touch OS subsystem of Java binding for half a year, the issue must be caused by a change in operating system.

I suppose Selenium can’t kill a driver process for the same (unknown yet) reason that you can’t kill it from the task manager. Something prevents the process from being stopped.

Try to check if reverting KB4339093 actually resolves the issue. Of course it’s just a workaround, but we have to identify the root cause before trying to fix the issue.