selenium+phantomjs报错:Unable to find a free port的分析和解决
2016-07-28 10:01
232 查看
selenium+phantomjs报错:Unable to find a free port的分析和解决
Table of Contents
1. 现象2. 分析
3. 解决办法
1 现象
在做项目时,发现在某台机器上使用selenium+phantomjs时报如下错误:java.lang.RuntimeException: Unable to find a free port at org.openqa.selenium.net.PortProber.findFreePort(PortProber.java:67) at org.openqa.selenium.phantomjs.PhantomJSDriverService$Builder.build(PhantomJSDriverService.java:443) ...
2 分析
通过跟踪源代码(org.openqa.selenium.net.PortProber.createAcceptablePort),发现:if (FIRST_PORT == LAST_PORT) { return FIRST_PORT; }
在该服务器上,FIRSTPORT = LASTPORT = 1024,因此总是返回1024。
查看服务器的可用本地端口配置,如下:
[gyx@interface01 ~]$ cat /proc/sys/net/ipv4/ip_local_port_range 1024 65535
因为这台机器的最低可用端口配置成了1024,而其他机器都比这个大很多,因此造成了上述问题。
3 解决办法
因为该服务器还有别的用处,不能随意修改可用端口配置,所以,暂时通过修改createAcceptablePort中相应代码解决问题。如下:if (FIRST_PORT == LAST_PORT) { // return FIRST_PORT; final int randomInt = random.nextInt(); System.out.println("randomInt = " + randomInt); final int portWithoutOffset = Math.abs(randomInt % (HIGHEST_PORT - START_OF_USER_PORTS + 1)); return portWithoutOffset + FIRST_PORT; }
Author: galaxy
Created: 2016-07-28 Thu 09:58
Emacs 24.5.6 (Org mode 8.2.10)
Validate
相关文章推荐
- JS 中document.URL 和 windows.location.href 的区别
- JavaScript中的上溢、下溢和被零整除
- 理解和使用 JavaScript 中的回调函数
- Javascript—正则表达式(操作指南)
- 浅谈JS正则表达式的RegExp对象和括号的使用
- [Effective JavaScript 笔记]第65条:不要在计算时阻塞事件队列
- 4000 jsp过滤器Filter配置过滤器汇总
- JavaScript强化教程——从简到繁
- JavaScript强化教程——从简到繁
- 基于js里调用函数时,函数名带括号和不带括号的区别
- JavaScript文件操作(1)-基础
- extjs form submit 总是执行failure
- JSP起源、JSP的运行原理、JSP的执行过程
- 浅谈js中调用函数时加不加括号的问题
- JS的节点的基本操作(CRUD)
- 在html里嵌入JavaScript
- 我的文章:JSP
- 关于JS变量和作用域详解
- js对象编程学习
- js导航制作