Skip to content

Commit 18087e2

Browse files
committed
[grid] removed a misleading lock from the grid model
1 parent 95d67c3 commit 18087e2

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed

java/src/org/openqa/selenium/grid/distributor/GridModel.java

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,12 @@ public void release(SessionId id) {
400400
}
401401
}
402402

403-
public void reserve(NodeStatus status, Slot slot) {
403+
/**
404+
* A helper to reserve a slot of a node. The writeLock must be acquired outside to ensure the view
405+
* of the NodeStatus is the current state, otherwise concurrent calls to amend will work with an
406+
* outdated view of slots.
407+
*/
408+
private void reserve(NodeStatus status, Slot slot) {
404409
Instant now = Instant.now();
405410

406411
Slot reserved =
@@ -490,30 +495,29 @@ public void updateHealthCheckCount(NodeId id, Availability availability) {
490495
}
491496
}
492497

498+
/**
499+
* A helper to replace the availability and a slot of a node. The writeLock must be acquired
500+
* outside to ensure the view of the NodeStatus is the current state, otherwise concurrent calls
501+
* to amend will work with an outdated view of slots.
502+
*/
493503
private void amend(Availability availability, NodeStatus status, Slot slot) {
494504
Set<Slot> newSlots = new HashSet<>(status.getSlots());
495505
newSlots.removeIf(s -> s.getId().equals(slot.getId()));
496506
newSlots.add(slot);
497507

498508
NodeStatus node = getNode(status.getNodeId());
499509

500-
Lock writeLock = lock.writeLock();
501-
writeLock.lock();
502-
try {
503-
nodes.remove(node);
504-
nodes.add(
505-
new NodeStatus(
506-
status.getNodeId(),
507-
status.getExternalUri(),
508-
status.getMaxSessionCount(),
509-
newSlots,
510-
availability,
511-
status.getHeartbeatPeriod(),
512-
status.getSessionTimeout(),
513-
status.getVersion(),
514-
status.getOsInfo()));
515-
} finally {
516-
writeLock.unlock();
517-
}
510+
nodes.remove(node);
511+
nodes.add(
512+
new NodeStatus(
513+
status.getNodeId(),
514+
status.getExternalUri(),
515+
status.getMaxSessionCount(),
516+
newSlots,
517+
availability,
518+
status.getHeartbeatPeriod(),
519+
status.getSessionTimeout(),
520+
status.getVersion(),
521+
status.getOsInfo()));
518522
}
519523
}

0 commit comments

Comments
 (0)