From 5d4790c1ca3387ccd53beee0af0d8fc649277ebd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Sautter?= Date: Tue, 12 Nov 2024 19:45:55 +0100 Subject: [PATCH] [grid] shutdown the server backend on stop --- .../grid/TemplateGridServerCommand.java | 18 +++++++++++-- .../grid/commands/EventBusCommand.java | 12 ++++++++- .../openqa/selenium/grid/commands/Hub.java | 19 ++++++++----- .../selenium/grid/commands/Standalone.java | 23 +++++++++------- .../distributor/httpd/DistributorServer.java | 16 ++++++++++- .../distributor/local/LocalDistributor.java | 14 +++++----- .../selenium/grid/node/httpd/NodeServer.java | 25 ++++++++++++++++- .../selenium/grid/node/local/LocalNode.java | 27 ++++++++++++++++++- .../selenium/grid/router/HandleSession.java | 19 +++++++++++-- .../openqa/selenium/grid/router/Router.java | 11 ++++++-- .../grid/router/httpd/RouterServer.java | 17 +++++++++++- .../sessionmap/httpd/SessionMapServer.java | 16 ++++++++++- .../httpd/NewSessionQueueServer.java | 16 ++++++++++- .../local/LocalNewSessionQueue.java | 3 +-- .../selenium/grid/router/DeploymentTypes.java | 2 +- 15 files changed, 200 insertions(+), 38 deletions(-) diff --git a/java/src/org/openqa/selenium/grid/TemplateGridServerCommand.java b/java/src/org/openqa/selenium/grid/TemplateGridServerCommand.java index 331057723516eb..35bf56b4978ea0 100644 --- a/java/src/org/openqa/selenium/grid/TemplateGridServerCommand.java +++ b/java/src/org/openqa/selenium/grid/TemplateGridServerCommand.java @@ -17,6 +17,7 @@ package org.openqa.selenium.grid; +import java.io.Closeable; import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -47,7 +48,17 @@ public Server asServer(Config initialConfig) { Handlers handler = createHandlers(config); return new NettyServer( - new BaseServerOptions(config), handler.httpHandler, handler.websocketHandler); + new BaseServerOptions(config), handler.httpHandler, handler.websocketHandler) { + + @Override + public void stop() { + try { + handler.close(); + } finally { + super.stop(); + } + } + }; } private static final String GRAPHQL = "/graphql"; @@ -77,7 +88,7 @@ protected static Routable baseRoute(String prefix, Route route) { protected abstract Handlers createHandlers(Config config); - public static class Handlers { + public abstract static class Handlers implements Closeable { public final HttpHandler httpHandler; public final BiFunction, Optional>> websocketHandler; @@ -89,5 +100,8 @@ public Handlers( this.websocketHandler = websocketHandler == null ? (str, sink) -> Optional.empty() : websocketHandler; } + + @Override + public abstract void close(); } } diff --git a/java/src/org/openqa/selenium/grid/commands/EventBusCommand.java b/java/src/org/openqa/selenium/grid/commands/EventBusCommand.java index 967e7d2ca7ad6c..e3a9424358066b 100644 --- a/java/src/org/openqa/selenium/grid/commands/EventBusCommand.java +++ b/java/src/org/openqa/selenium/grid/commands/EventBusCommand.java @@ -135,7 +135,17 @@ public Server asServer(Config initialConfig) { return httpResponse(false, "Status checking was interrupted"); } }), - Route.get("/readyz").to(() -> req -> new HttpResponse().setStatus(HTTP_NO_CONTENT)))); + Route.get("/readyz").to(() -> req -> new HttpResponse().setStatus(HTTP_NO_CONTENT)))) { + + @Override + public void stop() { + try { + bus.close(); + } finally { + super.stop(); + } + } + }; } @Override diff --git a/java/src/org/openqa/selenium/grid/commands/Hub.java b/java/src/org/openqa/selenium/grid/commands/Hub.java index 4bd1bfa7ef8cbe..fd1807e8333ea3 100644 --- a/java/src/org/openqa/selenium/grid/commands/Hub.java +++ b/java/src/org/openqa/selenium/grid/commands/Hub.java @@ -42,7 +42,6 @@ import org.openqa.selenium.grid.TemplateGridServerCommand; import org.openqa.selenium.grid.config.Config; import org.openqa.selenium.grid.config.Role; -import org.openqa.selenium.grid.distributor.Distributor; import org.openqa.selenium.grid.distributor.config.DistributorOptions; import org.openqa.selenium.grid.distributor.local.LocalDistributor; import org.openqa.selenium.grid.graphql.GraphqlHandler; @@ -57,9 +56,7 @@ import org.openqa.selenium.grid.server.EventBusOptions; import org.openqa.selenium.grid.server.NetworkOptions; import org.openqa.selenium.grid.server.Server; -import org.openqa.selenium.grid.sessionmap.SessionMap; import org.openqa.selenium.grid.sessionmap.local.LocalSessionMap; -import org.openqa.selenium.grid.sessionqueue.NewSessionQueue; import org.openqa.selenium.grid.sessionqueue.config.NewSessionQueueOptions; import org.openqa.selenium.grid.sessionqueue.local.LocalNewSessionQueue; import org.openqa.selenium.grid.web.CombinedHandler; @@ -120,7 +117,7 @@ protected Handlers createHandlers(Config config) { CombinedHandler handler = new CombinedHandler(); - SessionMap sessions = new LocalSessionMap(tracer, bus); + LocalSessionMap sessions = new LocalSessionMap(tracer, bus); handler.addHandler(sessions); BaseServerOptions serverOptions = new BaseServerOptions(config); @@ -141,7 +138,7 @@ protected Handlers createHandlers(Config config) { DistributorOptions distributorOptions = new DistributorOptions(config); NewSessionQueueOptions newSessionRequestOptions = new NewSessionQueueOptions(config); - NewSessionQueue queue = + LocalNewSessionQueue queue = new LocalNewSessionQueue( tracer, distributorOptions.getSlotMatcher(), @@ -151,7 +148,7 @@ protected Handlers createHandlers(Config config) { newSessionRequestOptions.getBatchSize()); handler.addHandler(queue); - Distributor distributor = + LocalDistributor distributor = new LocalDistributor( tracer, bus, @@ -212,7 +209,15 @@ protected Handlers createHandlers(Config config) { // these checks httpHandler = combine(httpHandler, Route.get("/readyz").to(() -> readinessCheck)); - return new Handlers(httpHandler, new ProxyWebsocketsIntoGrid(clientFactory, sessions)); + return new Handlers(httpHandler, new ProxyWebsocketsIntoGrid(clientFactory, sessions)) { + @Override + public void close() { + router.close(); + distributor.close(); + queue.close(); + bus.close(); + } + }; } @Override diff --git a/java/src/org/openqa/selenium/grid/commands/Standalone.java b/java/src/org/openqa/selenium/grid/commands/Standalone.java index 0a9601098848f2..c12ec74ccf3ed7 100644 --- a/java/src/org/openqa/selenium/grid/commands/Standalone.java +++ b/java/src/org/openqa/selenium/grid/commands/Standalone.java @@ -63,7 +63,6 @@ import org.openqa.selenium.grid.server.Server; import org.openqa.selenium.grid.sessionmap.SessionMap; import org.openqa.selenium.grid.sessionmap.local.LocalSessionMap; -import org.openqa.selenium.grid.sessionqueue.NewSessionQueue; import org.openqa.selenium.grid.sessionqueue.config.NewSessionQueueOptions; import org.openqa.selenium.grid.sessionqueue.local.LocalNewSessionQueue; import org.openqa.selenium.grid.web.CombinedHandler; @@ -145,7 +144,7 @@ protected Handlers createHandlers(Config config) { DistributorOptions distributorOptions = new DistributorOptions(config); NewSessionQueueOptions newSessionRequestOptions = new NewSessionQueueOptions(config); - NewSessionQueue queue = + LocalNewSessionQueue queue = new LocalNewSessionQueue( tracer, distributorOptions.getSlotMatcher(), @@ -155,7 +154,7 @@ protected Handlers createHandlers(Config config) { newSessionRequestOptions.getBatchSize()); combinedHandler.addHandler(queue); - Distributor distributor = + LocalDistributor distributor = new LocalDistributor( tracer, bus, @@ -171,9 +170,8 @@ protected Handlers createHandlers(Config config) { distributorOptions.getSlotMatcher()); combinedHandler.addHandler(distributor); - Routable router = - new Router(tracer, clientFactory, sessions, queue, distributor) - .with(networkOptions.getSpecComplianceChecks()); + Router router = new Router(tracer, clientFactory, sessions, queue, distributor); + Routable routerWithSpecChecks = router.with(networkOptions.getSpecComplianceChecks()); HttpHandler readinessCheck = req -> { @@ -192,8 +190,8 @@ protected Handlers createHandlers(Config config) { Routable appendRoute = Stream.of( - baseRoute(subPath, combine(router)), - hubRoute(subPath, combine(router)), + baseRoute(subPath, combine(routerWithSpecChecks)), + hubRoute(subPath, combine(routerWithSpecChecks)), graphqlRoute(subPath, () -> graphqlHandler)) .reduce(Route::combine) .get(); @@ -218,7 +216,14 @@ protected Handlers createHandlers(Config config) { httpHandler = combine(httpHandler, Route.get("/readyz").to(() -> readinessCheck)); Node node = createNode(config, bus, distributor, combinedHandler); - return new Handlers(httpHandler, new ProxyNodeWebsockets(clientFactory, node, subPath)); + return new Handlers(httpHandler, new ProxyNodeWebsockets(clientFactory, node, subPath)) { + @Override + public void close() { + router.close(); + distributor.close(); + queue.close(); + } + }; } @Override diff --git a/java/src/org/openqa/selenium/grid/distributor/httpd/DistributorServer.java b/java/src/org/openqa/selenium/grid/distributor/httpd/DistributorServer.java index 2a4db9a8b9e0e5..b48fc8c73131a0 100644 --- a/java/src/org/openqa/selenium/grid/distributor/httpd/DistributorServer.java +++ b/java/src/org/openqa/selenium/grid/distributor/httpd/DistributorServer.java @@ -31,6 +31,9 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.net.MediaType; +import java.io.Closeable; +import java.io.IOException; +import java.io.UncheckedIOException; import java.util.Collections; import java.util.Set; import java.util.logging.Level; @@ -118,7 +121,18 @@ protected Handlers createHandlers(Config config) { "message", "Distributor is ready"))))), get("/readyz").to(() -> readinessCheck)), - null); + null) { + @Override + public void close() { + if (distributor instanceof Closeable) { + try { + ((Closeable) distributor).close(); + } catch (IOException e) { + throw new UncheckedIOException(e); + } + } + } + }; } @Override diff --git a/java/src/org/openqa/selenium/grid/distributor/local/LocalDistributor.java b/java/src/org/openqa/selenium/grid/distributor/local/LocalDistributor.java index 280593e5df9e35..6489324ca2c075 100644 --- a/java/src/org/openqa/selenium/grid/distributor/local/LocalDistributor.java +++ b/java/src/org/openqa/selenium/grid/distributor/local/LocalDistributor.java @@ -18,6 +18,7 @@ package org.openqa.selenium.grid.distributor.local; import static com.google.common.collect.ImmutableSet.toImmutableSet; +import static org.openqa.selenium.concurrent.ExecutorServices.shutdownGracefully; import static org.openqa.selenium.grid.data.Availability.DOWN; import static org.openqa.selenium.grid.data.Availability.DRAINING; import static org.openqa.selenium.grid.data.Availability.UP; @@ -34,6 +35,7 @@ import com.google.common.collect.ImmutableSet; import dev.failsafe.Failsafe; import dev.failsafe.RetryPolicy; +import java.io.Closeable; import java.io.UncheckedIOException; import java.net.URI; import java.time.Duration; @@ -45,7 +47,6 @@ import java.util.Optional; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.Executor; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; @@ -118,7 +119,7 @@ @ManagedService( objectName = "org.seleniumhq.grid:type=Distributor,name=LocalDistributor", description = "Grid 4 node distributor") -public class LocalDistributor extends Distributor implements AutoCloseable { +public class LocalDistributor extends Distributor implements Closeable { private static final Logger LOG = Logger.getLogger(LocalDistributor.class.getName()); @@ -165,7 +166,7 @@ public class LocalDistributor extends Distributor implements AutoCloseable { return thread; }); - private final Executor sessionCreatorExecutor; + private final ExecutorService sessionCreatorExecutor; private final NewSessionQueue sessionQueue; @@ -752,9 +753,10 @@ public int getIdleSlots() { @Override public void close() { LOG.info("Shutting down Distributor executor service"); - purgeDeadNodesService.shutdown(); - nodeHealthCheckService.shutdown(); - newSessionService.shutdown(); + shutdownGracefully("Local Distributor - Purge Dead Nodes", purgeDeadNodesService); + shutdownGracefully("Local Distributor - Node Health Check", nodeHealthCheckService); + shutdownGracefully("Local Distributor - New Session Queue", newSessionService); + shutdownGracefully("Local Distributor - Session Creation", sessionCreatorExecutor); } private class NewSessionRunnable implements Runnable { diff --git a/java/src/org/openqa/selenium/grid/node/httpd/NodeServer.java b/java/src/org/openqa/selenium/grid/node/httpd/NodeServer.java index c86429aeaff645..f1ac54bb62ea76 100644 --- a/java/src/org/openqa/selenium/grid/node/httpd/NodeServer.java +++ b/java/src/org/openqa/selenium/grid/node/httpd/NodeServer.java @@ -30,6 +30,9 @@ import com.google.common.net.MediaType; import dev.failsafe.Failsafe; import dev.failsafe.RetryPolicy; +import java.io.Closeable; +import java.io.IOException; +import java.io.UncheckedIOException; import java.util.Collections; import java.util.Set; import java.util.concurrent.ExecutorService; @@ -172,7 +175,18 @@ protected Handlers createHandlers(Config config) { Route httpHandler = Route.combine(node, get("/readyz").to(() -> readinessCheck)); return new Handlers( - httpHandler, new ProxyNodeWebsockets(clientFactory, node, nodeOptions.getGridSubPath())); + httpHandler, new ProxyNodeWebsockets(clientFactory, node, nodeOptions.getGridSubPath())) { + @Override + public void close() { + if (node instanceof Closeable) { + try { + ((Closeable) node).close(); + } catch (IOException e) { + throw new UncheckedIOException(e); + } + } + } + }; } @Override @@ -225,6 +239,15 @@ public NettyServer start() { return this; } + + @Override + public void stop() { + try { + handler.close(); + } finally { + super.stop(); + } + } }; } diff --git a/java/src/org/openqa/selenium/grid/node/local/LocalNode.java b/java/src/org/openqa/selenium/grid/node/local/LocalNode.java index b42c557c910081..bb45cd00579dc1 100644 --- a/java/src/org/openqa/selenium/grid/node/local/LocalNode.java +++ b/java/src/org/openqa/selenium/grid/node/local/LocalNode.java @@ -18,6 +18,7 @@ package org.openqa.selenium.grid.node.local; import static com.google.common.collect.ImmutableSet.toImmutableSet; +import static org.openqa.selenium.concurrent.ExecutorServices.shutdownGracefully; import static org.openqa.selenium.grid.data.Availability.DOWN; import static org.openqa.selenium.grid.data.Availability.DRAINING; import static org.openqa.selenium.grid.data.Availability.UP; @@ -37,6 +38,7 @@ import com.google.common.cache.RemovalNotification; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; +import java.io.Closeable; import java.io.File; import java.io.IOException; import java.io.Serializable; @@ -114,7 +116,7 @@ @ManagedService( objectName = "org.seleniumhq.grid:type=Node,name=LocalNode", description = "Node running the webdriver sessions.") -public class LocalNode extends Node { +public class LocalNode extends Node implements Closeable { private static final Json JSON = new Json(); private static final Logger LOG = Logger.getLogger(LocalNode.class.getName()); @@ -139,6 +141,7 @@ public class LocalNode extends Node { private final Cache sessionToDownloadsDir; private final AtomicInteger pendingSessions = new AtomicInteger(); private final AtomicInteger sessionCount = new AtomicInteger(); + private final Runnable shutdown; protected LocalNode( Tracer tracer, @@ -301,6 +304,23 @@ protected LocalNode( heartbeatPeriod.getSeconds(), TimeUnit.SECONDS); + shutdown = + () -> { + if (heartbeatNodeService.isShutdown()) return; + + shutdownGracefully( + "Local Node - Session Cleanup " + externalUri, sessionCleanupNodeService); + shutdownGracefully( + "UploadTempFile Cleanup Node " + externalUri, uploadTempFileCleanupNodeService); + shutdownGracefully( + "DownloadTempFile Cleanup Node " + externalUri, downloadTempFileCleanupNodeService); + shutdownGracefully("HeartBeat Node " + externalUri, heartbeatNodeService); + + // ensure we do not leak running browsers + currentSessions.invalidateAll(); + currentSessions.cleanUp(); + }; + Runtime.getRuntime() .addShutdownHook( new Thread( @@ -311,6 +331,11 @@ protected LocalNode( new JMXHelper().register(this); } + @Override + public void close() { + shutdown.run(); + } + private void stopTimedOutSession(RemovalNotification notification) { if (notification.getKey() != null && notification.getValue() != null) { SessionSlot slot = notification.getValue(); diff --git a/java/src/org/openqa/selenium/grid/router/HandleSession.java b/java/src/org/openqa/selenium/grid/router/HandleSession.java index 12eebca1b59aa5..b199f0a51f356f 100644 --- a/java/src/org/openqa/selenium/grid/router/HandleSession.java +++ b/java/src/org/openqa/selenium/grid/router/HandleSession.java @@ -41,6 +41,7 @@ import java.util.logging.Level; import java.util.logging.Logger; import org.openqa.selenium.NoSuchSessionException; +import org.openqa.selenium.concurrent.ExecutorServices; import org.openqa.selenium.concurrent.GuardedRunnable; import org.openqa.selenium.grid.sessionmap.SessionMap; import org.openqa.selenium.grid.web.ReverseProxyHandler; @@ -59,7 +60,7 @@ import org.openqa.selenium.remote.tracing.Status; import org.openqa.selenium.remote.tracing.Tracer; -class HandleSession implements HttpHandler { +class HandleSession implements HttpHandler, Closeable { private static final Logger LOG = Logger.getLogger(HandleSession.class.getName()); @@ -99,6 +100,7 @@ public void close() { private final HttpClient.Factory httpClientFactory; private final SessionMap sessions; private final ConcurrentMap httpClients; + private final ScheduledExecutorService cleanUpHttpClientsCacheService; HandleSession(Tracer tracer, HttpClient.Factory httpClientFactory, SessionMap sessions) { this.tracer = Require.nonNull("Tracer", tracer); @@ -134,7 +136,7 @@ public void close() { } }; - ScheduledExecutorService cleanUpHttpClientsCacheService = + this.cleanUpHttpClientsCacheService = Executors.newSingleThreadScheduledExecutor( r -> { Thread thread = new Thread(r); @@ -243,4 +245,17 @@ private Callable loadSessionId( } }); } + + @Override + public void close() { + ExecutorServices.shutdownGracefully( + "HandleSession - Clean up http clients cache", cleanUpHttpClientsCacheService); + httpClients + .values() + .removeIf( + (entry) -> { + entry.httpClient.close(); + return true; + }); + } } diff --git a/java/src/org/openqa/selenium/grid/router/Router.java b/java/src/org/openqa/selenium/grid/router/Router.java index 5af111f242768a..d0e0ae362208f8 100644 --- a/java/src/org/openqa/selenium/grid/router/Router.java +++ b/java/src/org/openqa/selenium/grid/router/Router.java @@ -22,6 +22,7 @@ import static org.openqa.selenium.remote.http.Route.matching; import com.google.common.collect.ImmutableSet; +import java.io.Closeable; import org.openqa.selenium.grid.distributor.Distributor; import org.openqa.selenium.grid.sessionmap.SessionMap; import org.openqa.selenium.grid.sessionqueue.NewSessionQueue; @@ -35,12 +36,13 @@ import org.openqa.selenium.status.HasReadyState; /** A simple router that is aware of the selenium-protocol. */ -public class Router implements HasReadyState, Routable { +public class Router implements HasReadyState, Routable, Closeable { private final Routable routes; private final SessionMap sessions; private final Distributor distributor; private final NewSessionQueue queue; + private final HandleSession sessionHandler; public Router( Tracer tracer, @@ -55,7 +57,7 @@ public Router( this.queue = Require.nonNull("New Session Request Queue", queue); this.distributor = Require.nonNull("Distributor", distributor); - HandleSession sessionHandler = new HandleSession(tracer, clientFactory, sessions); + this.sessionHandler = new HandleSession(tracer, clientFactory, sessions); routes = combine( @@ -86,4 +88,9 @@ public boolean matches(HttpRequest req) { public HttpResponse execute(HttpRequest req) { return routes.execute(req); } + + @Override + public void close() { + sessionHandler.close(); + } } diff --git a/java/src/org/openqa/selenium/grid/router/httpd/RouterServer.java b/java/src/org/openqa/selenium/grid/router/httpd/RouterServer.java index d8797861cdf56d..7ff73e655cb883 100644 --- a/java/src/org/openqa/selenium/grid/router/httpd/RouterServer.java +++ b/java/src/org/openqa/selenium/grid/router/httpd/RouterServer.java @@ -31,6 +31,9 @@ import com.google.auto.service.AutoService; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; +import java.io.Closeable; +import java.io.IOException; +import java.io.UncheckedIOException; import java.net.URL; import java.time.Duration; import java.util.Collections; @@ -182,7 +185,19 @@ protected Handlers createHandlers(Config config) { // access to it. Routable routeWithLiveness = Route.combine(route, get("/readyz").to(() -> readinessCheck)); - return new Handlers(routeWithLiveness, new ProxyWebsocketsIntoGrid(clientFactory, sessions)); + return new Handlers(routeWithLiveness, new ProxyWebsocketsIntoGrid(clientFactory, sessions)) { + @Override + public void close() { + router.close(); + if (sessions instanceof Closeable) { + try { + ((Closeable) sessions).close(); + } catch (IOException e) { + throw new UncheckedIOException(e); + } + } + } + }; } @Override diff --git a/java/src/org/openqa/selenium/grid/sessionmap/httpd/SessionMapServer.java b/java/src/org/openqa/selenium/grid/sessionmap/httpd/SessionMapServer.java index 20385e23a3b8d3..64b07b11abbbfe 100644 --- a/java/src/org/openqa/selenium/grid/sessionmap/httpd/SessionMapServer.java +++ b/java/src/org/openqa/selenium/grid/sessionmap/httpd/SessionMapServer.java @@ -28,6 +28,9 @@ import com.google.auto.service.AutoService; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; +import java.io.Closeable; +import java.io.IOException; +import java.io.UncheckedIOException; import java.util.Collections; import java.util.Set; import java.util.logging.Level; @@ -105,7 +108,18 @@ protected Handlers createHandlers(Config config) { "message", "Session map is ready."))))), get("/readyz").to(() -> req -> new HttpResponse().setStatus(HTTP_NO_CONTENT))), - null); + null) { + @Override + public void close() { + if (sessions instanceof Closeable) { + try { + ((Closeable) sessions).close(); + } catch (IOException e) { + throw new UncheckedIOException(e); + } + } + } + }; } @Override diff --git a/java/src/org/openqa/selenium/grid/sessionqueue/httpd/NewSessionQueueServer.java b/java/src/org/openqa/selenium/grid/sessionqueue/httpd/NewSessionQueueServer.java index e0fc9e4abe99d2..e02eeeb2aa29e1 100644 --- a/java/src/org/openqa/selenium/grid/sessionqueue/httpd/NewSessionQueueServer.java +++ b/java/src/org/openqa/selenium/grid/sessionqueue/httpd/NewSessionQueueServer.java @@ -27,6 +27,9 @@ import com.google.auto.service.AutoService; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; +import java.io.Closeable; +import java.io.IOException; +import java.io.UncheckedIOException; import java.util.Collections; import java.util.Set; import java.util.logging.Level; @@ -105,7 +108,18 @@ protected Handlers createHandlers(Config config) { "message", "New Session Queue is ready."))))), get("/readyz").to(() -> req -> new HttpResponse().setStatus(HTTP_NO_CONTENT))), - null); + null) { + @Override + public void close() { + if (sessionQueue instanceof Closeable) { + try { + ((Closeable) sessionQueue).close(); + } catch (IOException e) { + throw new UncheckedIOException(e); + } + } + } + }; } @Override diff --git a/java/src/org/openqa/selenium/grid/sessionqueue/local/LocalNewSessionQueue.java b/java/src/org/openqa/selenium/grid/sessionqueue/local/LocalNewSessionQueue.java index 9bad66db5b6f76..619ecbc0d67db5 100644 --- a/java/src/org/openqa/selenium/grid/sessionqueue/local/LocalNewSessionQueue.java +++ b/java/src/org/openqa/selenium/grid/sessionqueue/local/LocalNewSessionQueue.java @@ -25,7 +25,6 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import java.io.Closeable; -import java.io.IOException; import java.time.Duration; import java.time.Instant; import java.util.Deque; @@ -453,7 +452,7 @@ public boolean isReady() { } @Override - public void close() throws IOException { + public void close() { shutdownGracefully(NAME, service); } diff --git a/java/test/org/openqa/selenium/grid/router/DeploymentTypes.java b/java/test/org/openqa/selenium/grid/router/DeploymentTypes.java index fe516132458c13..96273a5672bcb3 100644 --- a/java/test/org/openqa/selenium/grid/router/DeploymentTypes.java +++ b/java/test/org/openqa/selenium/grid/router/DeploymentTypes.java @@ -164,7 +164,7 @@ public Deployment start(Capabilities capabilities, Config additionalConfig) { "relax-checks = true", "", "[server]", - "", + "hostname = \"localhost\"", "registration-secret = \"colby\"", "", "[sessionqueue]",