Skip to content

Commit

Permalink
Fix leak of launcher on disconnect (#117)
Browse files Browse the repository at this point in the history
- afterDisconnect is called asynchronously from the deletion of the
Node. Ensure that we continue to process in the event that
`slaveComputer.getNode()` returns null, as we still have to ensure that
the launcher is torn down. Without this, SSHLauncher could sometimes
leak sockets.
  • Loading branch information
justfalter authored Jun 9, 2020
1 parent c0cfbe2 commit 7ea9d7a
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions src/main/java/org/jenkinsci/plugins/vSphereCloudLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -282,26 +282,27 @@ public void launch(SlaveComputer slaveComputer, TaskListener taskListener)
public synchronized void afterDisconnect(SlaveComputer slaveComputer, TaskListener taskListener) {
final vSphereCloudSlave vsSlave = (vSphereCloudSlave) slaveComputer.getNode();

if(vsSlave == null) {
vSphereCloud.Log(slaveComputer, taskListener, "Slave is null.");
return;
}
if (vsSlave.slaveIsStarting == Boolean.TRUE) {
vSphereCloud.Log(slaveComputer, taskListener, "Ignoring disconnect attempt because a connect attempt is in progress.");
return;
}
if (vsSlave.slaveIsDisconnecting == Boolean.TRUE) {
vSphereCloud.Log(slaveComputer, taskListener, "Already disconnecting on a separate thread");
return;
if (vsSlave != null) {
if (vsSlave.slaveIsStarting == Boolean.TRUE) {
vSphereCloud.Log(slaveComputer, taskListener, "Ignoring disconnect attempt because a connect attempt is in progress.");
return;
}
if (vsSlave.slaveIsDisconnecting == Boolean.TRUE) {
vSphereCloud.Log(slaveComputer, taskListener, "Already disconnecting on a separate thread");
return;
}
vsSlave.slaveIsDisconnecting = Boolean.TRUE;
} else {
vSphereCloud.Log(slaveComputer, taskListener, "Slave is null. Will still attempt to tear down launcher.");
}

if (slaveComputer.isTemporarilyOffline()) {
if (!(slaveComputer.getOfflineCause() instanceof VSphereOfflineCause)) {
vSphereCloud.Log(slaveComputer, taskListener, "Not disconnecting VM because it's not accepting tasks");
return;
}
}

vsSlave.slaveIsDisconnecting = Boolean.TRUE;
VSphere v = null;
boolean reconnect = false;
try {
Expand Down Expand Up @@ -380,8 +381,10 @@ public synchronized void afterDisconnect(SlaveComputer slaveComputer, TaskListen
v.disconnect();
v = null;
}
vsSlave.slaveIsDisconnecting = Boolean.FALSE;
vsSlave.slaveIsStarting = Boolean.FALSE;
if (vsSlave != null) {
vsSlave.slaveIsDisconnecting = Boolean.FALSE;
vsSlave.slaveIsStarting = Boolean.FALSE;
}

if (reconnect) {
slaveComputer.connect(false);
Expand Down

0 comments on commit 7ea9d7a

Please sign in to comment.