[🐛 Bug]: JS- ECONNREFUSED when using two WebDrivers and .quit()ing one
See original GitHub issueWhat 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:
- Created a year ago
- Comments:7 (1 by maintainers)
Top GitHub Comments
@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!
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.