wdio-selenium-standalone-service icon indicating copy to clipboard operation
wdio-selenium-standalone-service copied to clipboard

Session is not cleaning up all chromedriver processes

Open Gary-Osteen-Q2 opened this issue 7 years ago • 44 comments

For versions 0.0.8 and 0.0.9, the test run does not shut down all 2.31-x64-chromedriver processes when finished. This does not happen when using firefox/geckodriver. When running more than one spec, multiple 2.31-x64-chromedriver processes get started but one will always remain per test run. I have tested this with 1 and 2 specs in the wdio conf.

Current workaround that works for me:

Add this to your wdio.config.js file.

afterSession: async function(){
    // workaround to make sure the chromedriver shuts down
    await browser.end().pause(1000);
},
after: async function(){
    // workaround to make sure the chromedriver shuts down
    await browser.pause(1000);
}

Gary-Osteen-Q2 avatar Aug 22 '17 20:08 Gary-Osteen-Q2

Further testing shows this does not happen when you manually start the standalone jar before running the tests.

Gary-Osteen-Q2 avatar Aug 22 '17 21:08 Gary-Osteen-Q2

I am seeing the same issue with multiple specs. As a workaround, I set the Chrome capability maxInstances to 1 to run the specs serially.

// wdio.conf.js
capabilities: [{
    // maxInstances can get overwritten per capability. So if you have an in-house Selenium
    // grid with only 5 firefox instances available you can make sure that not more than
    // 5 instances get started at a time.
    maxInstances: 1,
    browserName: 'chrome'
}],

joshden avatar Sep 14 '17 18:09 joshden

Interesting if that works. This might be acceptable for smaller projects, but when you have a large collection, this would slow things down a lot if you are use to running 3 or more parallel instances.. That said, it might work for me for now, but won't be a sustainable workaround for long.

Gary-Osteen-Q2 avatar Sep 14 '17 18:09 Gary-Osteen-Q2

Yup I'm running into this same issue as well, and setting maxInstances to 1 is at best a temporary work around.

dangmai avatar Sep 27 '17 21:09 dangmai

The workaround does not work for me. With each manual run of a set of tests, a new 2.31-x64-chromedriver process is created, even if I have the maxInstances set to 1.

FlippieCoetser avatar Nov 02 '17 18:11 FlippieCoetser

A workaround, which is not ideal but works for me, is to use shelljs to run a kill command, in the afterSession hook:

shell.exec('taskkill /FI "IMAGENAME eq 2.33-x64-chromedriver" /F')

FlippieCoetser avatar Nov 03 '17 09:11 FlippieCoetser

I'm using chromedriver 2.33-x64 through the `services: [ 'selenium-standalone' ] and the chromedriver instances do not stop themselves even if I set maxInstances to 1.

    maxInstances: 1,
    capabilities: [
      {
        maxInstances: 1,
        browserName: 'chrome'
      }

in my package.json:

    "webdriverio": "4.9.9",
    "wdio-selenium-standalone-service": "0.0.9",

rgustavsson avatar Nov 24 '17 16:11 rgustavsson

@rgustavsson so it's more an issue of the selenium-standalone service?

christian-bromann avatar Nov 24 '17 16:11 christian-bromann

@christian-bromann not sure.

@Gary-Osteen-Q2 mentioned:

Further testing shows this does not happen when you manually start the standalone jar before running the tests.

So I was assuming that it works when running the selenium-standalone service manually.

rgustavsson avatar Nov 24 '17 16:11 rgustavsson

Bumping this. Any thoughts on what might be causing this yet? It's causing issues on our build servers as we get up to 100+ running instances of chromedriver! Plus it means we can't clean down the workspace between builds because of the same said running process.

mike-suggitt avatar Dec 19 '17 11:12 mike-suggitt

I have experienced this on both Chrome and Firefox with its geckodriver

Miladinho avatar Jan 12 '18 23:01 Miladinho

Me too. On Windows and Mac. Really problematic.

goatsy avatar Feb 07 '18 10:02 goatsy

Tried to do some research on this (on Windows).

It seems that selenium-standalone starts java.exe and then something (Java?) starts 2.33-x64-chromedriver. When kill is called (see below), it kills java.exe but not 2.33-x64-chromedriver: https://github.com/webdriverio/wdio-selenium-standalone-service/blob/ccb38ec3edd1b2bf80d3592ba3412e6bf0075179/lib/launcher.js#L36-L38

Seems like an issue in selenium-standalone, however I can't find anyone reporting it there, so maybe something specific in how it is invoked?

ashmind avatar Feb 11 '18 21:02 ashmind

image

Experiencing as well on windows 10:

 "wdio": "1.0.3",
    "wdio-browserstack-service": "0.1.14",
    "wdio-jasmine-framework": "0.3.2",
    "wdio-junit-reporter": "0.3.1",
    "wdio-selenium-standalone-service": "0.0.9",

phil-lgr avatar Feb 26 '18 19:02 phil-lgr

@ashmind did you find anything new? Debugging this morning to see what's up.

phil-lgr avatar Feb 27 '18 16:02 phil-lgr

I just tried putting a:

 after: async () => {
        await browser.pause(2000);
    },

and it seems to fix it, no more chromedriver left behind.

phil-lgr avatar Feb 27 '18 16:02 phil-lgr

mhm .. but why did it fix it when we wait in the afterHook?

christian-bromann avatar Feb 27 '18 16:02 christian-bromann

False alert 😅 I still get the idle at the end.. image

@christian-bromann any workaround you could think of or info I could gather?

phil-lgr avatar Feb 27 '18 17:02 phil-lgr

no idea, something must be up when trying to kill these processes

christian-bromann avatar Feb 27 '18 17:02 christian-bromann

@FlippieCoetser's solution seems to be the thing to do for now 🙏

phil-lgr avatar Feb 27 '18 17:02 phil-lgr

Hi , I am also facing the same issue.. @christian-bromann @phil-lgr is there any solution for it?

janardanb avatar Mar 06 '18 13:03 janardanb

@amolebhojane sorry but I can't look into this atm, any PRs or suggestion for fixes are highly appreciated

christian-bromann avatar Mar 06 '18 13:03 christian-bromann

I reproduced the problem using just selenium-standalone and webdriverio modules. I logged the issue for selenium-standalone.

I use a short delay after uninitializing the WebdriverIO client as a workaround to get the chromedriver process stopped:

const webdriverio = require('webdriverio')
const client = webdriverio.remote({...})
client.init()
  ...
  .end()
  // the following line helps stopping the chromedriver process after
  // killing the selenium process returned by the start method
  .pause(100)

prantlf avatar Mar 21 '18 17:03 prantlf

Ran into this today as well, as a workaround I've simply added this as an npm posttest command "posttest" : "taskkill /FI "IMAGENAME eq 2.36-x64-chromedriver" /F" based on @rgustavsson suggestion. Would really like to see a fix from selnium's side though.

ghost avatar Mar 27 '18 17:03 ghost

I've been running this as a post npm script:

const shell = require('shelljs/shell.js');
shell.exec('taskkill /IM chromedriver.exe /F', {silent: true});
shell.exec('kill -9 $(pgrep chromedriver)', {silent: true});

phil-lgr avatar Apr 03 '18 15:04 phil-lgr

I am having a similar issue. But I am also having the issue where the first test fails with the Connection Reset error. There were no lingering chromedriver sessions open. I run my tests and the first chrome test fails. This started all of a sudden too. I was having no failures and now it just keeps failing.

cuff-links avatar Apr 03 '18 23:04 cuff-links

Works fine against saucelabs because each test is run on its own machine. It's only when I run these locally.

cuff-links avatar Apr 03 '18 23:04 cuff-links

@silne30 maybe check https://github.com/webdriverio/wdio-selenium-standalone-service/issues/39

phil-lgr avatar Apr 04 '18 02:04 phil-lgr

Hi guys. I was trying to find most proper workaround for that issue for last couple of days. So far adding a script with taskkill /IM "chromedriver*" /F is good one but it will kill all drivers, which means you can't run more than 1 test instance at same time, since this will kill all chromedrivers. It is good way if you don't need to run 2 instance simultaneously. So far best workaround for me was to use afterAll with browser.driver.quit(), unfortunately after some updates afterAll stopped working and I made it as a method that I've put at the end of every test. There is an error but at least works and it doesn't affects the test's results

ichipev avatar Jun 14 '18 12:06 ichipev

I've tried all of the suggestions mentioned above and received inconsistent results. The only way I've gotten it to work consistently is by adding these lines to wdio.conf.js:

afterSession: function(){
    // workaround to make sure the chromedriver shuts down
    browser.end().pause(1000);
},
after: function(){
    // workaround to make sure the chromedriver shuts down
    browser.pause(1000);
}

I don't have a good explanation. Putting browser.end().pause(1000) in the after didn't work. Also tried with only the afterSession code and it didn't work.

rycornell avatar Jun 27 '18 12:06 rycornell