@@ -35,6 +35,7 @@ public class PortProber {
35
35
public static final int START_OF_USER_PORTS = 1024 ;
36
36
private static final Random random = new Random ();
37
37
private static final EphemeralPortRangeDetector ephemeralRangeDetector ;
38
+ private static final boolean inDocker = Boolean .parseBoolean (System .getenv ("SE_DOCKER" ));
38
39
39
40
static {
40
41
final Platform current = Platform .getCurrent ();
@@ -64,12 +65,12 @@ public static int findFreePort() {
64
65
}
65
66
66
67
/**
67
- * Returns a port that is within a probable free range. <p/> Based on the ports in
68
- * http://en.wikipedia.org/wiki/Ephemeral_ports, this method stays away from all well-known
69
- * ephemeral port ranges, since they can arbitrarily race with the operating system in
70
- * allocations. Due to the port-greedy nature of selenium this happens fairly frequently.
71
- * Staying within the known safe range increases the probability tests will run green quite
72
- * significantly.
68
+ * Returns a port that is within a probable free- range. <p/> Based on the ports in
69
+ * <a href=" http://en.wikipedia.org/wiki/Ephemeral_ports">...</a> , this method stays away
70
+ * from all well-known ephemeral port ranges, since they can arbitrarily race with the
71
+ * operating system in allocations. Due to the port-greedy nature of selenium this
72
+ * happens fairly frequently. Staying within the known safe range increases the probability
73
+ * tests will run green quite significantly.
73
74
*
74
75
* @return a random port number
75
76
*/
@@ -125,7 +126,12 @@ private static boolean isFree(String bindHost, int port) {
125
126
}
126
127
127
128
static int checkPortIsFree (int port ) {
128
- if (isFree ("localhost" , port ) && isFree ("0.0.0.0" , port ) && isFree ("::1" , port )) {
129
+ boolean localhostIsFree = isFree ("localhost" , port );
130
+ // We cannot check against all interfaces if the Grid is running inside Docker.
131
+ if (inDocker && localhostIsFree ) {
132
+ return port ;
133
+ }
134
+ if (localhostIsFree && isFree ("0.0.0.0" , port ) && isFree ("::1" , port )) {
129
135
return port ;
130
136
}
131
137
return -1 ;
0 commit comments