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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[馃悰 Bug]: JS- ECONNREFUSED when using two WebDrivers and .quit()ing one #10499

Closed
danielamar101 opened this issue Mar 31, 2022 · 7 comments
Closed

Comments

@danielamar101
Copy link

What happened?

So I have two built web drivers. On each I navigate to a specific site with a .get(). Then on one of them I use .quit() to close it. Then i try to use the second driver that is still open and try to navigate to a different site(really just do anything with the driver). Upon trying to use the second driver that should still be opened and using any API call, I get this ECONNREFUSED error. It appears that for some reason calling .quit() on the first driver also destroys the communication between selenium and the second driver.

I have pinpointed that this bug was introduced in Selenium 4.0.0-alpha.5 and has persisted until the latest version of selenium(4.1.1). Trying to do this should work as it works with versions prior to 4.0.0-alpha.5.

This same behavior also occurs MsEdgeDriver. Which leads me to believe this is a problem with selenium and not chromedriver. Also worth noting that this does not occur when using geckodriver.

How can we reproduce the issue?

const { exec, spawn } = require('child_process');
const webdriver = require('selenium-webdriver');
const BROWSER_NAME = webdriver.Browser.CHROME;
const chrome = require('selenium-webdriver/chrome');

async function startChromedriver() {
    const chromedriverExecutable = process.platform === 'win32' ? './chromedriver.exe' : './chromedriver';
    const child = spawn(chromedriverExecutable, { detached: true, stdio: 'ignore' });
    child.unref();
}


async function stopChromedriver() {
    return new Promise((resolve, reject) => {
      const cmd = process.platform === 'win32' ? 'taskkill /F /IM chromedriver.exe' : 'killall chromedriver';
      try {
        exec(cmd, (error, stdout, stderr) => {
          if (error) {
            resolve(false);
          }
          resolve(stdout);
        });
      } catch (error) {
        resolve(false);
      }
    });
}

async function getDriver() {
  const options = new chrome.Options();

  return new webdriver.Builder()
  .forBrowser(BROWSER_NAME)
  .withCapabilities(webdriver.Capabilities.chrome())
  .setChromeOptions(options).build();
}

async function doStuff(){

    await startChromedriver();

    const firstDriver = await getDriver();
    firstDriver.get('https://google.com')

    const secondDriver = await getDriver();
    await secondDriver.get('https://youtube.com')

    await firstDriver.quit();

    await secondDriver.get('https://reddit.com'); // <-- ECONNREFUSED here
    await secondDriver.quit();
}

doStuff();

Relevant log output

/Users/<me>/Desktop/Code/AsyncPractice/node_modules/selenium-webdriver/http/index.js:294
      onError(new Error(message))
              ^

Error: ECONNREFUSED connect ECONNREFUSED 127.0.0.1:60037
    at ClientRequest.<anonymous> (/Users/<me>/Desktop/Code/AsyncPractice/node_modules/selenium-webdriver/http/index.js:294:15)
    at ClientRequest.emit (node:events:394:28)
    at Socket.socketErrorListener (node:_http_client:447:9)
    at Socket.emit (node:events:394:28)
    at emitErrorNT (node:internal/streams/destroy:157:8)
    at emitErrorCloseNT (node:internal/streams/destroy:122:3)
    at processTicksAndRejections (node:internal/process/task_queues:83:21)

Operating System

Windows 10, MacOS 12.1

Selenium version

4.1.1

What are the browser(s) and version(s) where you see this issue?

Chrome 98.0.4758.102, Selenium 4.0.0-alpha.5-4.1.1

What are the browser driver(s) and version(s) where you see this issue?

ChromeDriver 98.0.4758.102 and latest EdgeDriver

Are you using Selenium Grid?

No response

@github-actions
Copy link

@danielamar101, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!

@diemol
Copy link
Member

diemol commented Apr 4, 2022

I can reproduce the issue and we are checking how to fix it. I just wonder if this was reported before...

@danielamar101
Copy link
Author

I tried querying all the issues to see if anyone had a similar issue. I couldn't find anything, but maybe someone titled it more obscurely.

@diemol diemol closed this as completed in 178b5d2 Apr 5, 2022
@danielamar101
Copy link
Author

danielamar101 commented Apr 5, 2022

@diemol Do you guys have any idea when you guys are targeting a release? Just wondering about how long we'll have to wait for this. And thank you for the quick diagnosis and fix. It is greatly appreciated. You guys are doing the angel's work!

@rrfaria
Copy link

rrfaria commented Apr 25, 2022

I've same issue
thanks for solution ... is there a way to use master until release is done?

@rrfaria
Copy link

rrfaria commented Apr 25, 2022

temp solution
change directly on node_modules

node_modules/selenium-webdriver/chromium.js

@github-actions
Copy link

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.

@github-actions github-actions bot locked and limited conversation to collaborators May 26, 2022
elgatov pushed a commit to elgatov/selenium that referenced this issue Jun 27, 2022
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

4 participants