Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions core/src/main/java/jenkins/model/Nodes.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,22 @@ public void addNode(final @NonNull Node node) throws IOException {
Jenkins.checkGoodName(node.getNodeName());
}

Node old = nodes.put(node.getNodeName(), node);
if (node != old) {
// Array used to safely capture the existing node from inside the lambda
final Node[] previousNode = new Node[1];

// Atomic swap: The map is locked ONLY for this tiny operation
nodes.compute(node.getNodeName(), (name, existingNode) -> {
Comment on lines +187 to +188
previousNode[0] = existingNode;
return node;
});

Node old = previousNode[0];
Comment on lines +184 to +193

if (node == old) {
// Fixes #26692: Sync the active Computer for in-place mutated nodes.
// Executed OUTSIDE the compute block to prevent lock-order inversions and deadlocks.
Jenkins.get().updateComputers(node);
} else {
handleAddedNode(node, old);
}
}
Expand Down
Loading