diff --git a/java/src/org/openqa/selenium/grid/node/docker/DockerFlags.java b/java/src/org/openqa/selenium/grid/node/docker/DockerFlags.java index 02af7f7c2dd41..827f1deab4074 100644 --- a/java/src/org/openqa/selenium/grid/node/docker/DockerFlags.java +++ b/java/src/org/openqa/selenium/grid/node/docker/DockerFlags.java @@ -54,6 +54,17 @@ public class DockerFlags implements HasRoles { @ConfigValue(section = DockerOptions.DOCKER_SECTION, name = "port", example = "2375") private Integer dockerPort; + @Parameter( + names = {"--docker-server-start-timeout"}, + description = + "Max time (in seconds) to wait for the server to successfully start up, before cancelling" + + " the process.") + @ConfigValue( + section = DockerOptions.DOCKER_SECTION, + name = "server-start-timeout", + example = "55") + private Integer serverStartTimeout; + @Parameter( names = {"--docker", "-D"}, description = diff --git a/java/src/org/openqa/selenium/grid/node/docker/DockerOptions.java b/java/src/org/openqa/selenium/grid/node/docker/DockerOptions.java index 5866375988ddb..c714373eeb7af 100644 --- a/java/src/org/openqa/selenium/grid/node/docker/DockerOptions.java +++ b/java/src/org/openqa/selenium/grid/node/docker/DockerOptions.java @@ -25,6 +25,7 @@ import com.google.common.collect.Multimap; import java.net.URI; import java.net.URISyntaxException; +import java.time.Duration; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -63,6 +64,7 @@ public class DockerOptions { static final String DEFAULT_DOCKER_URL = "unix:/var/run/docker.sock"; static final String DEFAULT_VIDEO_IMAGE = "false"; static final int DEFAULT_MAX_SESSIONS = Runtime.getRuntime().availableProcessors(); + static final int DEFAULT_SERVER_START_TIMEOUT = 60; private static final String DEFAULT_DOCKER_NETWORK = "bridge"; private static final Logger LOG = Logger.getLogger(DockerOptions.class.getName()); private static final Json JSON = new Json(); @@ -104,6 +106,11 @@ private URI getDockerUri() { } } + private Duration getServerStartTimeout() { + return Duration.ofSeconds( + config.getInt(DOCKER_SECTION, "server-start-timeout").orElse(DEFAULT_SERVER_START_TIMEOUT)); + } + private boolean isEnabled(Docker docker) { if (!config.getAll(DOCKER_SECTION, "configs").isPresent()) { return false; @@ -179,6 +186,7 @@ public Map> getDockerSessionFactories( tracer, clientFactory, options.getSessionTimeout(), + getServerStartTimeout(), docker, getDockerUri(), image, diff --git a/java/src/org/openqa/selenium/grid/node/docker/DockerSessionFactory.java b/java/src/org/openqa/selenium/grid/node/docker/DockerSessionFactory.java index 65b322674662f..6f6ab71caef05 100644 --- a/java/src/org/openqa/selenium/grid/node/docker/DockerSessionFactory.java +++ b/java/src/org/openqa/selenium/grid/node/docker/DockerSessionFactory.java @@ -91,6 +91,7 @@ public class DockerSessionFactory implements SessionFactory { private final Tracer tracer; private final HttpClient.Factory clientFactory; private final Duration sessionTimeout; + private final Duration serverStartTimeout; private final Docker docker; private final URI dockerUri; private final Image browserImage; @@ -108,6 +109,7 @@ public DockerSessionFactory( Tracer tracer, HttpClient.Factory clientFactory, Duration sessionTimeout, + Duration serverStartTimeout, Docker docker, URI dockerUri, Image browserImage, @@ -123,6 +125,7 @@ public DockerSessionFactory( this.tracer = Require.nonNull("Tracer", tracer); this.clientFactory = Require.nonNull("HTTP client", clientFactory); this.sessionTimeout = Require.nonNull("Session timeout", sessionTimeout); + this.serverStartTimeout = Require.nonNull("Server start timeout", serverStartTimeout); this.docker = Require.nonNull("Docker command", docker); this.dockerUri = Require.nonNull("Docker URI", dockerUri); this.browserImage = Require.nonNull("Docker browser image", browserImage); @@ -181,7 +184,7 @@ public Either apply(CreateSessionRequest sess "Waiting for server to start (container id: %s, url %s)", container.getId(), remoteAddress)); try { - waitForServerToStart(client, Duration.ofMinutes(1)); + waitForServerToStart(client, serverStartTimeout); } catch (TimeoutException e) { span.setAttribute(AttributeKey.ERROR.getKey(), true); span.setStatus(Status.CANCELLED); @@ -367,7 +370,7 @@ private Container startVideoContainer( clientFactory.createClient(ClientConfig.defaultConfig().baseUri(videoContainerUrl)); try { LOG.fine(String.format("Waiting for video recording... (id: %s)", videoContainer.getId())); - waitForServerToStart(videoClient, Duration.ofMinutes(1)); + waitForServerToStart(videoClient, serverStartTimeout); } catch (Exception e) { videoContainer.stop(Duration.ofSeconds(10)); String message =