Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Webdriver: java.net.BindException: Address already in use: connect

Tags:

java

webdriver

While running webdriver, 3 minutes into running, I get the following exception and Webdriver crashes.

I am using only one webdriver instance and one FirefoxDriver profile.

Exception in thread "main" org.openqa.selenium.WebDriverException:
java.net.BindException: Address already in use: connect
System info: os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1',
java.version: '1.6.0_18'
Driver info: driver.version: remote
        at
org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:
341)
        at
org.openqa.selenium.firefox.FirefoxDriver.execute(FirefoxDriver.java:
234)
        at
org.openqa.selenium.remote.RemoteWebDriver.findElements(RemoteWebDriver.java:
173)
        at
org.openqa.selenium.remote.RemoteWebDriver.findElementsByXPath(RemoteWebDriver.java:
231)
        at org.openqa.selenium.By$6.findElements(By.java:200)
        at
org.openqa.selenium.remote.RemoteWebDriver.findElements(RemoteWebDriver.java:
158)

Caused by: java.net.BindException: Address already in use: connect
        at java.net.PlainSocketImpl.socketConnect(Native Method)
        at java.net.PlainSocketImpl.doConnect(Unknown Source)
        at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
        at java.net.PlainSocketImpl.connect(Unknown Source)
        at java.net.SocksSocketImpl.connect(Unknown Source)
        at java.net.Socket.connect(Unknown Source)
        at
org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:
123)
        at
org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:
133)
        at
org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:
149)
        at
org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:
108)
        at
org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:
415)
        at
org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:
641)
        at
org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:
211)
        at
org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.execute(NewProfileExtensionConnection.java:
125)
        at org.openqa.selenium.firefox.FirefoxDriver
$LazyCommandExecutor.execute(FirefoxDriver.java:341)
        at
org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:
328)
        ... 11 more 
like image 394
KJW Avatar asked Dec 01 '10 01:12

KJW


1 Answers

I had this problem in a set of machines where some ran Win2003, some ran Windows7 and many ran Linux. What I found was that closing all the java processes and restarting helped a little, especially after running the java processes for many days on end. And, what helped very significantly was Avoiding TCP/IP Port Exhaustion on MSDN with MaxUserPort of 10000 (twice the default of 5000) and TcpTimedWaitDelay of 30 (minimum) on the Win2003 machine which was running the standalone selenium grid as the hub role. REBOOT after changing - per instructions on MSDN.

The Windows "netstat -b" command was very useful on the Win2003 machine in order to confirm that dozens and dozens of tcp/ip connections were open (ports 4444 and 5555); those were quite obviously part of the Selenium Grid (v2) system.

In Java, I use driver.quit(); at the end of each test method. I tried driver.close() and lost the ability to run more than one test in a row.

I can now run 250 tests with 0 exceptions showing up on the Hub's java console.

like image 125
user424855 Avatar answered Oct 13 '22 00:10

user424855