Skip to content
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 cases where SlaveTemplate has been removed #429

Merged
merged 1 commit into from
Feb 14, 2020
Merged

Handle cases where SlaveTemplate has been removed #429

merged 1 commit into from
Feb 14, 2020

Conversation

res0nance
Copy link
Contributor

Recently we encoutered an issue where when a SlaveTemplate is removed but an old Instance that uses this slave template still exists it will throw an NPE.

This PR annotates the methods and reworks the code to handle such scenarios more gracefully.

@@ -411,9 +416,9 @@ public boolean verifyServerHostKey(String hostname, int port, String serverHostK
}
}

private String getEC2HostAddress(EC2Computer computer) throws InterruptedException {
private static String getEC2HostAddress(EC2Computer computer, SlaveTemplate template) throws InterruptedException {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why static? I cannot see when it's needed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed it to static because it doesn't need any value in the actual class itself so it should have been static from the start as its not required to be tied to any instance of the Launcher

Copy link
Contributor

@fcojfernandez fcojfernandez Feb 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

your words make sense, but it looks weird to me having a static private method which is not called within a static block of code. Anyway, I'm not blocking the PR because of this. It's just a matter of taste and I only wanted to know if there were other reasons. I will let the others give their opinion if applies and I'm approving the PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh for me I used to mostly write C++, so a static method has the benefit of not passing in an additional parameter(The this pointer). So the habit stayed with me.

Copy link
Contributor

@fcojfernandez fcojfernandez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good

@@ -411,9 +416,9 @@ public boolean verifyServerHostKey(String hostname, int port, String serverHostK
}
}

private String getEC2HostAddress(EC2Computer computer) throws InterruptedException {
private static String getEC2HostAddress(EC2Computer computer, SlaveTemplate template) throws InterruptedException {
Copy link
Contributor

@fcojfernandez fcojfernandez Feb 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

your words make sense, but it looks weird to me having a static private method which is not called within a static block of code. Anyway, I'm not blocking the PR because of this. It's just a matter of taste and I only wanted to know if there were other reasons. I will let the others give their opinion if applies and I'm approving the PR.

Copy link
Member

@jvz jvz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. The use of IOException could potentially be replaced with something more specific, though I can't think of anything besides maybe IllegalStateException.

@res0nance
Copy link
Contributor Author

LGTM. The use of IOException could potentially be replaced with something more specific, though I can't think of anything besides maybe IllegalStateException.

Can't use IllegalState as its not caught outside and does not terminate the instance. It might also lead to a FD leak scenario(which seems to be a bug in core)

@res0nance
Copy link
Contributor Author

If there are no objections to merging it as is, I will be merging tomorrow

@res0nance res0nance merged commit 6ad20f0 into jenkinsci:master Feb 14, 2020
@res0nance res0nance deleted the null-slavetemplate branch February 14, 2020 02:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants