Skip to content

Commit 3bcf237

Browse files
committed
[grid] close the HttpClient after the session is gone
1 parent 7881635 commit 3bcf237

File tree

5 files changed

+12
-7
lines changed

5 files changed

+12
-7
lines changed

java/src/org/openqa/selenium/grid/node/DefaultActiveSession.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,13 @@
2828
import org.openqa.selenium.remote.Dialect;
2929
import org.openqa.selenium.remote.SessionId;
3030
import org.openqa.selenium.remote.http.HttpClient;
31-
import org.openqa.selenium.remote.http.HttpHandler;
3231
import org.openqa.selenium.remote.http.HttpRequest;
3332
import org.openqa.selenium.remote.http.HttpResponse;
3433
import org.openqa.selenium.remote.tracing.Tracer;
3534

3635
public class DefaultActiveSession extends BaseActiveSession {
3736

38-
private final HttpHandler handler;
37+
private final ReverseProxyHandler handler;
3938
private final String killUrl;
4039

4140
protected DefaultActiveSession(
@@ -68,6 +67,6 @@ public HttpResponse execute(HttpRequest req) throws UncheckedIOException {
6867

6968
@Override
7069
public void stop() {
71-
// no-op
70+
handler.close();
7271
}
7372
}

java/src/org/openqa/selenium/grid/node/config/DriverServiceSessionFactory.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,8 @@ public Either<WebDriverException, ActiveSession> apply(CreateSessionRequest sess
204204
Instant.now()) {
205205
@Override
206206
public void stop() {
207-
try (fClient) {
208-
service.stop();
209-
}
207+
super.stop();
208+
service.stop();
210209
}
211210
});
212211
} catch (Exception e) {

java/src/org/openqa/selenium/grid/node/docker/DockerSession.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ public void stop() {
6767
}
6868
saveLogs();
6969
container.stop(Duration.ofMinutes(1));
70+
super.stop();
7071
}
7172

7273
private void saveLogs() {

java/src/org/openqa/selenium/grid/router/HandleSession.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ public UsageCountingReverseProxyHandler(
9090

9191
@Override
9292
public void close() {
93+
// must not call super.close() here, to ensure the HttpClient stays alive
9394
// set the last use here, to ensure we have to calculate the real inactivity of the client
9495
entry.lastUse = Instant.now();
9596
entry.inUse.decrementAndGet();

java/src/org/openqa/selenium/grid/web/ReverseProxyHandler.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
import org.openqa.selenium.remote.tracing.Span;
3434
import org.openqa.selenium.remote.tracing.Tracer;
3535

36-
public class ReverseProxyHandler implements HttpHandler {
36+
public class ReverseProxyHandler implements HttpHandler, AutoCloseable {
3737

3838
private static final Logger LOG = Logger.getLogger(ReverseProxyHandler.class.getName());
3939

@@ -101,4 +101,9 @@ public HttpResponse execute(HttpRequest req) throws UncheckedIOException {
101101
return resp;
102102
}
103103
}
104+
105+
@Override
106+
public void close() {
107+
upstream.close();
108+
}
104109
}

0 commit comments

Comments
 (0)