Skip to content

Commit

Permalink
Merge pull request #1479 from Dohbedoh/JENKINS-72441
Browse files Browse the repository at this point in the history
[JENKINS-72441] Prevent lock contention on `KubernetesLauncher#isLaunchSupported`
  • Loading branch information
Vlatombe authored Dec 8, 2023
2 parents 7b3f77f + dde23cd commit 6faf0fb
Showing 1 changed file with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
Expand All @@ -69,7 +70,7 @@ public class KubernetesLauncher extends JNLPLauncher {

private static final Logger LOGGER = Logger.getLogger(KubernetesLauncher.class.getName());

private boolean launched;
private final AtomicBoolean launched = new AtomicBoolean(false);

/**
* Provisioning exception if any.
Expand All @@ -87,8 +88,8 @@ public KubernetesLauncher() {
}

@Override
public synchronized boolean isLaunchSupported() {
return !launched;
public boolean isLaunchSupported() {
return !launched.get();
}

@Override
Expand All @@ -105,7 +106,7 @@ public synchronized void launch(SlaveComputer computer, TaskListener listener) {
if (node == null) {
throw new IllegalStateException("Node has been removed, cannot launch " + computer.getName());
}
if (launched) {
if (launched.get()) {
LOGGER.log(INFO, "Agent has already been launched, activating: {0}", node.getNodeName());
computer.setAcceptingTasks(true);
return;
Expand Down Expand Up @@ -241,7 +242,7 @@ else if (httpCode == 409 && e.getMessage().contains("Operation cannot be fulfill
}

computer.setAcceptingTasks(true);
launched = true;
launched.set(true);
try {
// We need to persist the "launched" setting...
node.save();
Expand Down

0 comments on commit 6faf0fb

Please sign in to comment.