diff --git a/java/src/org/openqa/selenium/grid/node/DefaultActiveSession.java b/java/src/org/openqa/selenium/grid/node/DefaultActiveSession.java index 94fc774d06406..4c38c48a4a5a0 100644 --- a/java/src/org/openqa/selenium/grid/node/DefaultActiveSession.java +++ b/java/src/org/openqa/selenium/grid/node/DefaultActiveSession.java @@ -28,14 +28,13 @@ import org.openqa.selenium.remote.Dialect; import org.openqa.selenium.remote.SessionId; import org.openqa.selenium.remote.http.HttpClient; -import org.openqa.selenium.remote.http.HttpHandler; import org.openqa.selenium.remote.http.HttpRequest; import org.openqa.selenium.remote.http.HttpResponse; import org.openqa.selenium.remote.tracing.Tracer; public class DefaultActiveSession extends BaseActiveSession { - private final HttpHandler handler; + private final ReverseProxyHandler handler; private final String killUrl; protected DefaultActiveSession( @@ -68,6 +67,6 @@ public HttpResponse execute(HttpRequest req) throws UncheckedIOException { @Override public void stop() { - // no-op + handler.close(); } } diff --git a/java/src/org/openqa/selenium/grid/node/config/DriverServiceSessionFactory.java b/java/src/org/openqa/selenium/grid/node/config/DriverServiceSessionFactory.java index 4ec5fe7d0a2e6..b69aa518d30da 100644 --- a/java/src/org/openqa/selenium/grid/node/config/DriverServiceSessionFactory.java +++ b/java/src/org/openqa/selenium/grid/node/config/DriverServiceSessionFactory.java @@ -190,7 +190,6 @@ public Either apply(CreateSessionRequest sess caps = readPrefixedCaps(capabilities, caps); span.addEvent("Driver service created session", attributeMap); - final HttpClient fClient = client; return Either.right( new DefaultActiveSession( tracer, @@ -204,9 +203,8 @@ public Either apply(CreateSessionRequest sess Instant.now()) { @Override public void stop() { - try (fClient) { - service.stop(); - } + super.stop(); + service.stop(); } }); } catch (Exception e) { diff --git a/java/src/org/openqa/selenium/grid/node/docker/DockerSession.java b/java/src/org/openqa/selenium/grid/node/docker/DockerSession.java index 3851347abbb19..6608e7cb7bdca 100644 --- a/java/src/org/openqa/selenium/grid/node/docker/DockerSession.java +++ b/java/src/org/openqa/selenium/grid/node/docker/DockerSession.java @@ -67,6 +67,7 @@ public void stop() { } saveLogs(); container.stop(Duration.ofMinutes(1)); + super.stop(); } private void saveLogs() { diff --git a/java/src/org/openqa/selenium/grid/router/HandleSession.java b/java/src/org/openqa/selenium/grid/router/HandleSession.java index b199f0a51f356..58c36ed4cc27d 100644 --- a/java/src/org/openqa/selenium/grid/router/HandleSession.java +++ b/java/src/org/openqa/selenium/grid/router/HandleSession.java @@ -90,6 +90,7 @@ public UsageCountingReverseProxyHandler( @Override public void close() { + // must not call super.close() here, to ensure the HttpClient stays alive // set the last use here, to ensure we have to calculate the real inactivity of the client entry.lastUse = Instant.now(); entry.inUse.decrementAndGet(); diff --git a/java/src/org/openqa/selenium/grid/web/ReverseProxyHandler.java b/java/src/org/openqa/selenium/grid/web/ReverseProxyHandler.java index b6a98bb323992..8fb0b91eb3bd8 100644 --- a/java/src/org/openqa/selenium/grid/web/ReverseProxyHandler.java +++ b/java/src/org/openqa/selenium/grid/web/ReverseProxyHandler.java @@ -33,7 +33,7 @@ import org.openqa.selenium.remote.tracing.Span; import org.openqa.selenium.remote.tracing.Tracer; -public class ReverseProxyHandler implements HttpHandler { +public class ReverseProxyHandler implements HttpHandler, AutoCloseable { private static final Logger LOG = Logger.getLogger(ReverseProxyHandler.class.getName()); @@ -101,4 +101,9 @@ public HttpResponse execute(HttpRequest req) throws UncheckedIOException { return resp; } } + + @Override + public void close() { + upstream.close(); + } }