Webdriver:java.net.BindException:地址已在使用:连接
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4320397/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Webdriver: java.net.BindException: Address already in use: connect
提问by KJW
While running webdriver, 3 minutes into running, I get the following exception and Webdriver crashes.
在运行 webdriver 时,运行 3 分钟后,出现以下异常并且 Webdriver 崩溃。
I am using only one webdriver instance and one FirefoxDriver profile.
我只使用了一个 webdriver 实例和一个 FirefoxDriver 配置文件。
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.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
采纳答案by user207421
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.
你的出站端口用完了。这意味着您已经在两分钟内执行了数千个出站连接。解决方案:使用连接池,或减慢程序速度。
回答by user424855
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 MSDNwith MaxUserPortof 10000(twice the default of 5000) and TcpTimedWaitDelayof 30(minimum) on the Win2003 machine which was running the standalone selenium grid as the hub role. REBOOT after changing - per instructions on MSDN.
我在一组机器上遇到了这个问题,其中一些运行 Win2003,一些运行 Windows7,许多运行 Linux。我发现关闭所有 java 进程并重新启动有一点帮助,尤其是在连续运行 java 进程很多天之后。而且,在运行独立 selenium 网格作为集线器角色的 Win2003 机器上,使用MaxUserPort为10000(默认值为 5000 的两倍)和TcpTimedWaitDelay为30(最小值)的情况下,帮助非常重要的是避免 MSDN 上的 TCP/IP 端口耗尽。更改后重新启动 - 根据 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.
Windows "netstat -b" 命令在 Win2003 机器上非常有用,用于确认数十个 tcp/ip 连接已打开(端口 4444 和 5555);这些显然是 Selenium Grid (v2) 系统的一部分。
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.
在 Java 中,我使用 driver.quit(); 在每个测试方法结束时。我尝试了 driver.close() 并失去了连续运行多个测试的能力。
I can now run 250 tests with 0 exceptions showing up on the Hub's java console.
我现在可以运行 250 个测试,在 Hub 的 java 控制台上显示 0 个异常。
回答by Chris S.
If your situation is like mine, where you
如果你的情况和我一样,你在哪里
- open port 1
- connect to machine
- ??
- close port 1
- open port 1
- connect to different machine
- 打开端口 1
- 连接到机器
- ??
- 关闭端口 1
- 打开端口 1
- 连接到不同的机器
try adding socket.setSoLinger(true, 0);
directly before socket.close();
.
尝试socket.setSoLinger(true, 0);
直接在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.
这会强制操作系统释放套接字,而不是将其置于某种TIME_WAIT
状态。