-
Notifications
You must be signed in to change notification settings - Fork 690
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle DescribeInstances failures when creating new instance #414
Open
dbnicholson
wants to merge
2
commits into
jenkinsci:master
Choose a base branch
from
dbnicholson:new-instance-no-data
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -162,7 +162,19 @@ public EC2AbstractSlave(String name, String instanceId, String templateDescripti | |
this.amiType = amiType; | ||
this.maxTotalUses = maxTotalUses; | ||
readResolve(); | ||
fetchLiveInstanceData(true); | ||
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(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @thoulen also made a point that this terminateInstance call can fail if the api gets throttled |
||
throw e; | ||
} | ||
} | ||
|
||
@Deprecated | ||
|
@@ -541,7 +553,7 @@ protected boolean isAlive(boolean force) { | |
* Much of the EC2 data is beyond our direct control, therefore we need to refresh it from time to time to ensure we | ||
* reflect the reality of the instances. | ||
*/ | ||
private void fetchLiveInstanceData(boolean force) throws AmazonClientException { | ||
private void fetchLiveInstanceData(boolean force, int timeout) throws AmazonClientException { | ||
/* | ||
* If we've grabbed the data recently, don't bother getting it again unless we are forced | ||
*/ | ||
|
@@ -563,7 +575,7 @@ private void fetchLiveInstanceData(boolean force) throws AmazonClientException { | |
|
||
Instance i = null; | ||
try { | ||
i = CloudHelper.getInstanceWithRetry(getInstanceId(), getCloud()); | ||
i = CloudHelper.getInstanceWithRetry(getInstanceId(), getCloud(), timeout); | ||
} catch (InterruptedException e) { | ||
// We'll just retry next time we test for idleness. | ||
LOGGER.fine("InterruptedException while get " + getInstanceId() | ||
|
@@ -594,6 +606,10 @@ private void fetchLiveInstanceData(boolean force) throws AmazonClientException { | |
} | ||
} | ||
|
||
private void fetchLiveInstanceData(boolean force) throws AmazonClientException { | ||
fetchLiveInstanceData(force, 25); | ||
} | ||
|
||
/* | ||
* Clears all existing tag data so that we can force the instance into a known state | ||
*/ | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When does this get called? If its during a provision operation, having such a long timeout might not be ideal as during provisioning the queue lock is held which means during this 1 minute builds you start won't be queued up and builds can't be picked up by nodes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not totally sure what Jenkins context this is called in, but I'm pretty sure it doesn't block other builds from queuing. That said, it already blocks for up to 25 seconds. This just extends it to 60 seconds.
We could try leaving out this commit and just having the commit that tries to terminate the instance if it couldn't get the information about the instance. That would hopefully keep it from getting deadlocked.
Yet another possible fix is for the EC2 plugin to keep track of which instances it launched and actively terminate any other instances it finds in EC2 with the same details. I didn't look into that, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we keep the timeout to be the same and explore increasing it if it does not solve the issue completely