Skip to content

Commit

Permalink
[FIXED JENKINS-40223] Avoid NPE when ssh connection fails and termina…
Browse files Browse the repository at this point in the history
…te agents under any Exception (#234)

* [JENKINS-40223] Avoid NPE when ssh connection fails and terminate agents under any Exception before the idlePeriod happens.

* [JENKINS-40223] Manage the NPE
  • Loading branch information
fbelzunc authored and Francis Upton IV committed Aug 18, 2017
1 parent 78ea67a commit 7e8d576
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
21 changes: 21 additions & 0 deletions src/main/java/hudson/plugins/ec2/EC2ComputerLauncher.java
Expand Up @@ -122,11 +122,32 @@ public void launch(SlaveComputer slaveComputer, TaskListener listener) {
launch(computer, listener, computer.describeInstance());
} catch (AmazonClientException e) {
e.printStackTrace(listener.error(e.getMessage()));
if (slaveComputer.getNode() instanceof EC2AbstractSlave) {
LOGGER.log(Level.FINE, String.format("Terminating the ec2 agent %s due a problem launching or connecting to it", slaveComputer.getName()), e);
EC2AbstractSlave ec2AbstractSlave = (EC2AbstractSlave) slaveComputer.getNode();
if (ec2AbstractSlave != null) {
ec2AbstractSlave.terminate();
}
}
} catch (IOException e) {
e.printStackTrace(listener.error(e.getMessage()));
if (slaveComputer.getNode() instanceof EC2AbstractSlave) {
LOGGER.log(Level.FINE, String.format("Terminating the ec2 agent %s due a problem launching or connecting to it", slaveComputer.getName()), e);
EC2AbstractSlave ec2AbstractSlave = (EC2AbstractSlave) slaveComputer.getNode();
if (ec2AbstractSlave != null) {
ec2AbstractSlave.terminate();
}
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
e.printStackTrace(listener.error(e.getMessage()));
if (slaveComputer.getNode() instanceof EC2AbstractSlave) {
LOGGER.log(Level.FINE, String.format("Terminating the ec2 agent %s due a problem launching or connecting to it", slaveComputer.getName()), e);
EC2AbstractSlave ec2AbstractSlave = (EC2AbstractSlave) slaveComputer.getNode();
if (ec2AbstractSlave != null) {
ec2AbstractSlave.terminate();
}
}
}

}
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/hudson/plugins/ec2/ssh/EC2UnixLauncher.java
Expand Up @@ -306,7 +306,9 @@ private boolean bootstrap(EC2Computer computer, TaskListener listener) throws IO
return false;
}
} finally {
bootstrapConn.close();
if (bootstrapConn != null) {
bootstrapConn.close();
}
}
return true;
}
Expand Down

0 comments on commit 7e8d576

Please sign in to comment.