Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Webdriver:java.net.BindException:地址已在使用中:connect_Java_Webdriver - Fatal编程技术网

Webdriver:java.net.BindException:地址已在使用中:connect

Webdriver:java.net.BindException:地址已在使用中:connect,java,webdriver,Java,Webdriver,在运行webdriver时,运行3分钟后,我遇到以下异常,webdriver崩溃 我只使用一个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: 'x8

在运行webdriver时,运行3分钟后,我遇到以下异常,webdriver崩溃

我只使用一个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$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 

您的出站端口快用完了。这意味着您在两分钟内完成了数千个出站连接。解决方案:使用连接池,或者放慢程序的速度。

如果您的情况与我的情况类似,那么

  • 打开端口1
  • 连接到机器
  • ?
  • 关闭端口1
  • 打开端口1
  • 连接到不同的机器
  • 尝试添加
    socket.setSoLinger(true,0)
    就在
    socket.close()之前

    像这样:

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

    这迫使操作系统释放套接字,而不是将其置于等待状态。

    我在一组机器中遇到了这个问题,其中一些机器运行Win2003,一些机器运行Windows7,许多机器运行Linux。我发现关闭所有java进程并重新启动会有一些帮助,特别是在连续运行了很多天的java进程之后。而且,在运行独立selenium网格作为中心角色的Win2003机器上,使用MaxUserPort10000(默认值为5000的两倍)和TcpTimedWaitDelay30(最低值)非常有帮助。更改后重新启动-按照MSDN上的说明

    Windows“netstat-b”命令在Win2003机器上非常有用,用于确认数十个tcp/ip连接已打开(端口4444和5555);这些显然是硒网格(v2)系统的一部分

    在Java中,我使用driver.quit();在每个试验方法结束时。我尝试了driver.close(),但失去了连续运行多个测试的能力


    我现在可以运行250个测试,在中心的java控制台上显示0个异常

    你能发布一个问题发生的代码片段吗?我意识到在通过WebDriver test
    ((JavascriptExecutor)driver)加载的每个页面上运行Javascript的可能重复。executeScript(javascripthere)
    导致了这个问题。但是,我需要在被测试的页面上运行Javascript,您可以这样做,但不需要测试不现实的情况。实用客户端不会打开数千个出站连接。你这样做只是因为你想让服务器饱和。因此,答案是使用更多的硬件客户端。不确定通过连接池可以看到什么。一旦出站连接使用完毕,我如何关闭它们?我对WebDriver一无所知,我无法回答这个问题,但我会寻找close()或disconnect()方法。它还强制TCP丢弃传输中的任何数据,并强制对等方处理错误EconReset,而不是正常的流结束。这两个都是对应用程序的语义更改。不推荐。