Skip to content
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

Chromedriver quit() method doesn't close all chrome.exe processes #6317

Closed
nemirof opened this issue Aug 22, 2018 · 24 comments
Closed

Chromedriver quit() method doesn't close all chrome.exe processes #6317

nemirof opened this issue Aug 22, 2018 · 24 comments

Comments

@nemirof
Copy link

nemirof commented Aug 22, 2018

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!

@circa10a
Copy link

circa10a commented Aug 22, 2018

Also having similar issue with seleniumJS 4 / Chrome 68 / chromedriver 2.38 & 2.41 via headless where driver.quit() isn't working:

 NoSuchSessionError: This driver instance does not have a valid session ID (did you call WebDriver.quit()?) and may no longer be used.

@richman555
Copy link

We opened a similar type issue (6314) yesterday except for IE. I can't guarantee its the same issue, but the resulting behavior seems to be the same. This issue started about a week ago after taking a MS update. Otherwise, wish I could be more helpful!

@JackWangAndRose
Copy link

We met same issue,On chrome and chromedriver

@tictac-freshmint
Copy link

I have the same issue, both on Windows 7 and Windows 10 since a few weeks. I already tried a lot of things, nothing worked yet. For instance I tried dozens of ways to terminate chromedriver.exe, as an administrator, on commandline with various commands, with PowerShell and with tools from Sysinternals. Only a Windows reboot kills these processes, log off and log on does not terminate them.

Also I disabled the virus scanner and reverted to previous versions of Selenium and webdrivers, but it did not help.

It happens with webdrivers for Chrome, IE and Edge (we do not use other browsers), apparently only since a few weeks. Sometimes the processes can be terminated however when ¨driver.quit()¨ is executed. Maybe it has to do with an automatically installed Windows update? In a forum someone wrote that he uninstalled

More and more zombie processes slow down the test execution performance and tests fail because of timeouts then.

There is a blog https://blogs.technet.microsoft.com/markrussinovich/2005/08/17/unkillable-processes/ which explains the reasons for that in Windows and how it can be analyzed by debugging. But I am no expert on this and I do not know yet if the Windows administators will allow to install the ¨Windows Debugging Tools¨. But maybe someone else is familiar with this and can install them in order to investigate the reason?

Also interesting seemed to be this page: https://randomascii.wordpress.com/2018/02/11/zombie-processes-are-eating-your-memory/ It mentions a tool called ¨FindZombieHandles¨, but our very secured system prevents me to use such a tool. Maybe someone else has the oppurtunity and can report if it helps to understand why exactly the webdriver processes cannot be terminated?

In a forum which I cannot find anymore someone wrote that after uninstalling a recent Windows update (KB something with 818 I think at the end) the problem with webdriver zombie processes could be solved. But that update was not installed on our computer. Now I see here #6314 which says that it occured after KB4339093, which is installed on our machine since a few weeks. I maybe try to convince the admins to uninstall it.

@barancev
Copy link
Member

barancev commented Sep 5, 2018

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.

@tictac-freshmint
Copy link

In our case the problem seems to be gone since last week. Maybe there was some Windows update which fixed it.

@dewanprakash
Copy link

We are facing identically same issue with
Selenium v3.8.1
Chrome drvier v2.41.x
Chrome browser v69
Windows 7

@claytonwinders
Copy link

Facing a similar issue:
selenium-webdriver 4.0.0-alpha
Chrome driver 2.42
Chrome browser v69
AWS Linux

Using an async function in an express get method in node, after running successfully once and calling driver.quit() cannot call again due to chromedriver still running

@temadivnich
Copy link

Hi all
We met the same issue, do you know when it will be solved ?

@MattKeenum
Copy link

We are encountering the same issue. 3 Google Chrome (chrome.exe) process still sits in memory after calling driver.quit(). They tend to take between 25-30% CPU and roughly 20-25 MB in memory each. Currently, calling taskkill on chrome.exe is the only way to get rid of em.

Selenium 3.12.1
ChromeDriver 2.43.0
Chrome Browser 70.0.3538.110

@heyitsmesuraj
Copy link

I have the same issue when page timeout reached and there is no exception for Webdriver.Quit() and does not kill the processes.
OneTimeSetUp: OpenQA.Selenium.WebDriverException : The HTTP request to the remote WebDriver server for URL http://localhost:55323/session/f4b61f62299ebcf485d710ff65d9184c/element/0.1432089089670756-3/click timed out after 60 seconds.
----> System.Net.WebException : The request was aborted: The operation has timed out.
Exception doesn't have a stacktrace

@hacrot3000
Copy link

I have same issue, lot of chrome cause my test server freeze because runs out of ram.

@schreibd
Copy link

schreibd commented Dec 20, 2018

Same here.
Want to run my tests in a jenkins build and need to be sure these processes get killed after methodcall...
However, setting the webDriver to null kills the process for me

@MattKeenum
Copy link

We have been able to fix the issue of the chrome.exe zombie processes being left over. We were passing "--no-sandbox" argument to the ChromeDirver. Removing this argument from the driver initialization solved the issue. We no longer have the zombie processes left over after calling driver.quit

@spetrovas
Copy link

spetrovas commented Dec 28, 2018

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);
}`

@MattKeenum
Copy link

MattKeenum commented Dec 29, 2018

@spetrovas Try removing the "no-sandbox" argument

@andiramuttakim
Copy link

My headless chrome cannot run without --no-sandbox flag.
Already setup a user as mentioned on this page, but it didn't work.

@spetrovas
Copy link

spetrovas commented Jan 2, 2019

Sorry, about confusion - I meant to say "In our code we always had "--no-sandbox" COMMENTED OUT and the problem is still there."

I corrected my previous comment.

The error in the node log file:
[2019-01-02 22:03:36] [SEVERE] Unable to kill process java.lang.ProcessImpl@f0de26

is coming from this class and method:
org.openqa.selenium.os.OsProcess class
public int destroy()

What I was trying to point out is this comment in the code:
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);
}
. . . .
}

Our Se Grid runs on Windows 10 (AWS WS):
Selenium 3.14.0
Chromedriver 2.43
Google Chrome 71.0.3578.98 (Official Build) (64-bit) (cohort: Stable)

It might be the problem related to Windows but it still can be the problem in Selenium code as well. From the code it is apparently seen that there is no proper process.destroy implemented for Windows platform, and then the process is simply tried to be destroyed forcibly.

And my question is - is anyone going to look into that problem?

@laurinkeithdavis
Copy link

We are having this same issue as well. Why was this closed?

@cgoldberg
Copy link
Contributor

Why was this closed?

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

@fenixadar
Copy link

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

@spetrovas
Copy link

That does not help when using remote web driver with Se Grid which provides remote service.

@AMG888
Copy link

AMG888 commented Mar 13, 2019

Just noting for anyone caught out by a similar experience. I found a number of zombie instances of chrome persisted after I aborted builds running on jenkins.

Naturally, if they are aborted mid flight, they don't hit the teardown method and terminate processes using .close and/or .quit

Taskkill mopped them up but maybe worth bearing in mind

@claytonwinders
Copy link

We moved to using the standalone-chrome docker container for testing. This allowed us to have timeouts on the docker container when tests seemed to either escape all the catches for .close() or didn't work. It has been a bit difficult to work into codeception integration but for standalone selenium tests with python or node it has been great

@lock lock bot locked and limited conversation to collaborators Aug 14, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests