Skip to content

Commit 025c61d

Browse files
committed
Better hostname setting from server options if no network is present
1 parent b835acc commit 025c61d

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

java/server/src/org/openqa/selenium/grid/server/BaseServerOptions.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,21 @@
1717

1818
package org.openqa.selenium.grid.server;
1919

20+
import org.openqa.selenium.WebDriverException;
2021
import org.openqa.selenium.grid.config.Config;
2122
import org.openqa.selenium.grid.config.ConfigException;
23+
import org.openqa.selenium.net.HostIdentifier;
2224
import org.openqa.selenium.net.NetworkUtils;
2325
import org.openqa.selenium.net.PortProber;
2426

2527
import java.net.URI;
2628
import java.net.URISyntaxException;
2729
import java.util.Optional;
30+
import java.util.logging.Logger;
2831

2932
public class BaseServerOptions {
3033

34+
private static final Logger LOG = Logger.getLogger(BaseServerOptions.class.getName());
3135
private final Config config;
3236
private int port = -1;
3337

@@ -70,7 +74,15 @@ public int getMaxServerThreads() {
7074
public URI getExternalUri() {
7175
// Assume the host given is addressable if it's been set
7276
String host = getHostname()
73-
.orElseGet(() -> new NetworkUtils().getNonLoopbackAddressOfThisMachine());
77+
.orElseGet(() -> {
78+
try {
79+
return new NetworkUtils().getNonLoopbackAddressOfThisMachine();
80+
} catch (WebDriverException e) {
81+
String name = HostIdentifier.getHostName();
82+
LOG.info("No network connection, guessing name: " + name);
83+
return name;
84+
}
85+
});
7486

7587
int port = getPort();
7688

0 commit comments

Comments
 (0)