Skip to content

Commit be30b62

Browse files
committed
[grid] Decrementing pending sessions for draining to stop method
Using a listener for this was an overhead as this could be done when the session is being stopped in the Node. Additionally, we were not checking in the listener if the session actually belonged to the Node.
1 parent 8daaa06 commit be30b62

1 file changed

Lines changed: 9 additions & 13 deletions

File tree

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

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
import org.openqa.selenium.grid.data.NodeId;
4343
import org.openqa.selenium.grid.data.NodeStatus;
4444
import org.openqa.selenium.grid.data.Session;
45-
import org.openqa.selenium.grid.data.SessionClosedEvent;
4645
import org.openqa.selenium.grid.data.Slot;
4746
import org.openqa.selenium.grid.data.SlotId;
4847
import org.openqa.selenium.grid.jmx.JMXHelper;
@@ -217,18 +216,6 @@ private LocalNode(
217216
heartbeatPeriod.getSeconds(),
218217
TimeUnit.SECONDS);
219218

220-
bus.addListener(SessionClosedEvent.listener(id -> {
221-
// Shouldn't we check that the session actually belongs to this Node?
222-
// Listen to session terminated events, so we know when to fire the NodeDrainComplete event
223-
if (this.isDraining()) {
224-
int done = pendingSessions.decrementAndGet();
225-
if (done <= 0) {
226-
LOG.info("Firing node drain complete message");
227-
bus.fire(new NodeDrainComplete(this.getId()));
228-
}
229-
}
230-
}));
231-
232219
Runtime.getRuntime().addShutdownHook(new Thread(this::stopAllSessions));
233220
new JMXHelper().register(this);
234221
}
@@ -487,6 +474,15 @@ public void stop(SessionId id) throws NoSuchSessionException {
487474

488475
currentSessions.invalidate(id);
489476
tempFileSystems.invalidate(id);
477+
478+
// Decrement pending sessions if Node is draining
479+
if (this.isDraining()) {
480+
int done = pendingSessions.decrementAndGet();
481+
if (done <= 0) {
482+
LOG.info("Node draining complete!");
483+
bus.fire(new NodeDrainComplete(this.getId()));
484+
}
485+
}
490486
}
491487

492488
private void stopAllSessions() {

0 commit comments

Comments
 (0)