Skip to content

Commit 9c9cd27

Browse files
committed
[grid] ensure the current session count is correct
1 parent 18087e2 commit 9c9cd27

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,8 +377,10 @@ public boolean isReady() {
377377
@VisibleForTesting
378378
@ManagedAttribute(name = "CurrentSessions")
379379
public int getCurrentSessionCount() {
380+
// we need the exact size, see javadoc of Cache.size
381+
long n = currentSessions.asMap().values().stream().count();
380382
// It seems wildly unlikely we'll overflow an int
381-
return Math.toIntExact(currentSessions.size());
383+
return Math.toIntExact(n);
382384
}
383385

384386
@VisibleForTesting
@@ -1005,6 +1007,9 @@ public HealthCheck getHealthCheck() {
10051007
public void drain() {
10061008
bus.fire(new NodeDrainStarted(getId()));
10071009
draining = true;
1010+
// Ensure the pendingSessions counter will not be decremented by timed out sessions not included
1011+
// in the currentSessionCount and the NodeDrainComplete will be raised to early.
1012+
currentSessions.cleanUp();
10081013
int currentSessionCount = getCurrentSessionCount();
10091014
if (currentSessionCount == 0) {
10101015
LOG.info("Firing node drain complete message");

0 commit comments

Comments
 (0)