question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[🐛 Bug]: JS- ECONNREFUSED when using two WebDrivers and .quit()ing one

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
danielamar101commented, 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!

0reactions
github-actions[bot]commented, May 26, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Intermittent Selenium ECONNREFUSED errors on CircleCI
WARNING: This is merely a hack and is by no means a proper solution, but it is the only one that appears to...
Read more >
webdriverio/webdriverio - Gitter
I need change window size in webdriver (but only for 1 test). I tried browser.getWindowSize, browser.setWindowSize but only error.
Read more >
Setting up your own test automation environment
In this article, we will teach you how to install your own automation environment and run your own tests using Selenium/WebDriver and a ......
Read more >
The chromedriver crashes/lose connection when navigate to ...
1. What changed *after* ChromeDriver v2.35 that is causing the connection refused error? I don't see this issue when I run the test...
Read more >
Follow up of Econnrefused ::1:27017 - MongoDB
I post here as a follow up of Econnrefused ::1:27017 as it is no longer possible to post replies there. When connecting to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found