Skip to content

Commit

Permalink
Try to terminate new instance if no data could be retrieved
Browse files Browse the repository at this point in the history
If DescribeInstances did not return any data, send a termination request
for it. If it shows up later, it would be included in capacity
calculations and Jenkins could refuse to instantiate new nodes if the
maximum capacity was reached.
  • Loading branch information
dbnicholson committed Oct 31, 2019
1 parent 18143a9 commit 929d580
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/main/java/hudson/plugins/ec2/EC2AbstractSlave.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,19 @@ public EC2AbstractSlave(String name, String instanceId, String templateDescripti
this.amiType = amiType;
this.maxTotalUses = maxTotalUses;
readResolve();
// Wait up to 1 minute for the instance to show up
fetchLiveInstanceData(true, 60);
try {
// Wait up to 1 minute for the instance to show up
fetchLiveInstanceData(true, 60);
} catch (com.amazonaws.AmazonClientException e) {
/*
* If DescribeInstances didn't return any information about this
* instance, try to terminate it so that if it does come up later
* it doesn't affect capacity calculations.
*/
LOGGER.log(Level.WARNING, "Failed to get instance data for new instance " + getInstanceId(), ", terminating");
terminateInstance();
throw e;
}
}

@Deprecated
Expand Down

0 comments on commit 929d580

Please sign in to comment.