Question

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 
Was it helpful?

Solution

You're running out of outbound ports. That means you've performed thousands of outbound connections within two minutes. Solution: use a connection pool, or slow your program down.

OTHER TIPS

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.

If your situation is like mine, where you

  1. open port 1
  2. connect to machine
  3. ??
  4. close port 1
  5. open port 1
  6. connect to different machine

try adding socket.setSoLinger(true, 0); directly before socket.close();.

Like so:

socket.setSoLinger(true, 0);
socket.close();

This forces the OS to release the socket, rather than putting it in a TIME_WAIT state.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top