Skip to content

Commit

Permalink
[grid]: Ensure sessions are closed on the node properly
Browse files Browse the repository at this point in the history
We do this by combining code paths for both the user
facing `stop` command, and the listener used by the
guava cache when it evicts an entry.
  • Loading branch information
shs96c committed Feb 10, 2019
1 parent 7192c86 commit 524b37d
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions java/server/src/org/openqa/selenium/grid/node/local/LocalNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,14 @@ private LocalNode(
.expireAfterAccess(sessionTimeout)
.ticker(ticker)
.removalListener((RemovalListener<SessionId, SessionAndHandler>) notification -> {
// Attempt to stop the session
notification.getValue().stop();
bus.fire(new SessionClosedEvent(notification.getKey()));
// If we were invoked explicitly, then return: we know what we're doing.
if (!notification.wasEvicted()) {
return;
}

try (Span span = tracer.createSpan("node.evict-session", null)) {
killSession(span, notification.getValue());
}
})
.build();

Expand Down Expand Up @@ -221,22 +226,30 @@ public void executeWebDriverCommand(HttpRequest req, HttpResponse resp) {
public void stop(SessionId id) throws NoSuchSessionException {
try (Span span = tracer.createSpan("node.stop-session", tracer.getActiveSpan())) {

span.addTag("session.id", id);

Objects.requireNonNull(id, "Session ID has not been set");

SessionAndHandler session = currentSessions.getIfPresent(id);
if (session == null) {
throw new NoSuchSessionException("Cannot find session with id: " + id);
}

span.addTag("session.capabilities", session.getCapabilities());
span.addTag("session.uri", session.getUri());

currentSessions.invalidate(id);
session.stop();
killSession(span, session);
}
}

private void killSession(Span span, SessionAndHandler session) {
span.addTag("session.id", session.getId());
span.addTag("session.capabilities", session.getCapabilities());
span.addTag("session.uri", session.getUri());

currentSessions.invalidate(session.getId());
session.stop();
// Attempt to stop the session
session.stop();
bus.fire(new SessionClosedEvent(session.getId()));
}


@Override
public NodeStatus getStatus() {
Map<Capabilities, Integer> available = new ConcurrentHashMap<>();
Expand Down

0 comments on commit 524b37d

Please sign in to comment.