Skip to content

Commit 9656da7

Browse files
committed
[grid] Sending a DELETE when a session times out.
This is a more graceful way to stop an idle session. Grid was only killing the browser driver, and in some cases the browser was left open. This change attempts to avoid that by stopping the session with a DELETE. Fixes #10820
1 parent 829e476 commit 9656da7

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

java/src/org/openqa/selenium/grid/node/local/LocalNode.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
import java.util.concurrent.TimeUnit;
9292
import java.util.concurrent.atomic.AtomicBoolean;
9393
import java.util.concurrent.atomic.AtomicInteger;
94+
import java.util.logging.Level;
9495
import java.util.logging.Logger;
9596
import java.util.stream.Collectors;
9697

@@ -180,12 +181,17 @@ private LocalNode(
180181
.ticker(ticker)
181182
.removalListener((RemovalListener<SessionId, SessionSlot>) notification -> {
182183
if (notification.getKey() != null && notification.getValue() != null) {
183-
// Attempt to stop the session
184184
SessionSlot slot = notification.getValue();
185-
SessionId sessionId = notification.getKey();
185+
SessionId id = notification.getKey();
186+
if (notification.wasEvicted()) {
187+
// Session is timing out, stopping it by sending a DELETE
188+
LOG.log(Level.INFO, () -> String.format("Session id %s timed out, stopping...", id));
189+
slot.execute(new HttpRequest(DELETE, "/session/" + id));
190+
}
191+
// Attempt to stop the session
186192
slot.stop();
187193
// Invalidate temp file system
188-
this.tempFileSystems.invalidate(sessionId);
194+
this.tempFileSystems.invalidate(id);
189195
// Decrement pending sessions if Node is draining
190196
if (this.isDraining()) {
191197
int done = pendingSessions.decrementAndGet();

0 commit comments

Comments
 (0)