Skip to content

Commit

Permalink
Better hostname setting from server options if no network is present
Browse files Browse the repository at this point in the history
  • Loading branch information
shs96c committed Oct 15, 2019
1 parent b835acc commit 025c61d
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,21 @@

package org.openqa.selenium.grid.server;

import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.grid.config.Config;
import org.openqa.selenium.grid.config.ConfigException;
import org.openqa.selenium.net.HostIdentifier;
import org.openqa.selenium.net.NetworkUtils;
import org.openqa.selenium.net.PortProber;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.Optional;
import java.util.logging.Logger;

public class BaseServerOptions {

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

Expand Down Expand Up @@ -70,7 +74,15 @@ public int getMaxServerThreads() {
public URI getExternalUri() {
// Assume the host given is addressable if it's been set
String host = getHostname()
.orElseGet(() -> new NetworkUtils().getNonLoopbackAddressOfThisMachine());
.orElseGet(() -> {
try {
return new NetworkUtils().getNonLoopbackAddressOfThisMachine();
} catch (WebDriverException e) {
String name = HostIdentifier.getHostName();
LOG.info("No network connection, guessing name: " + name);
return name;
}
});

int port = getPort();

Expand Down

0 comments on commit 025c61d

Please sign in to comment.