-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Enable jib.httpTimeout system property for HTTP connection and read timeout #656
Conversation
3b8a10f
to
710c02f
Compare
Hold on. Chatted with @coollog, and I'll rework this. |
8f42890
to
4654fac
Compare
I think this is good for review. The next step after this PR is to check the system property value at the frontend to print out warnings, if necessary. |
@@ -69,6 +69,11 @@ | |||
} | |||
} | |||
|
|||
private static int getHttpTimeout() { | |||
int httpTimeout = Integer.getInteger("jib.httpTimeout", 20000); |
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.
Is there a way we could reuse the default from the Google HTTP client? Or not set an HTTP timeout to allow it to use the default from the HTTP library?
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.
The Google HTTP client doesn't define the public static constant, so I'll pursue the latter approach.
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.
Looks good! Just a small question.
@@ -103,6 +103,15 @@ public static Initializer initializer(String serverUrl, String repository) { | |||
return new Initializer(serverUrl, repository); | |||
} | |||
|
|||
@Nullable | |||
private static Integer getHttpTimeout() { |
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.
Is using null
a common way to do this? If not, I was thinking maybe use negative to indicate absence?
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 think it's not uncommon to use null
to indicate a field is unset or uninitialized, or something is absent. Using a negative value works too. However, it won't be distinguishable from the user wrongly giving a negative value. That will matter if we error out on a negative timeout value as you said.
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.
Okay sounds good 👍 let's add a javadoc explicitly mentioning that null
means the caller should use some default.
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.
Ah, you weren't talking about a field here. I see what you meant. I'll think about the API-aspect of this method.
@Nullable | ||
private static Integer getHttpTimeout() { | ||
Integer httpTimeout = Integer.getInteger("jib.httpTimeout"); | ||
if (httpTimeout != null && httpTimeout >= 0) { |
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 think we could do just return Integer.getInteger("jib.httpTimeout", null)
since in the negative case, we probably want to error (thrown by HttpRequest#setConnectTimeout
)
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 was thinking showing a warning with a negative value, instead of errorring out. Do you think it's not good?
Anyways, if we decide to error out, I'll probably detect it and fail at the frontends with better error messages, rather than just displaying up an unfriendly stack trace from Preconditions.checkArgument()
with no message.
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 think either way is good. I lean towards the errorring since the case I could think of where negative could show up is if the user may have meant to type another timeout and accidentally put a minus sign in front - in which case, a warning may be lost in the logs to a different error when the connection fails.
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 see. I think then the same argument applies to non-parsable string values. The user could accidentally put any non-digit characters, so it also makes sense to error out on non-parsable strings. Going for errorring on both cases?
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.
Yea, I think in the non-parsable version, this already errors, since Integer#getInteger
would throw a NumberFormatException
.
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.
Alright, errorring on both cases. (BTW, Integer.getInteger()
doesn't throw NumberFormatException
. parseInt()
does, OTOH.)
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.
Ah right, looks like the getInteger(String nm, Integer val)
one catches and ignores the NumberFormatException
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.
Will update the code tomorrow, but I'm thinking of doing
Integer httpTimeout = null; // implies using the default timeout
String timeoutValue = System.getProperty("jib.httpTimeout");
if (timeoutValue != null) {
httpTimeout = Integer.parseInt(timeoutValue);
if (httpTimeout < 0) {
throw new RegistryAuthenticationFailedException("Negative value of jib.httpTimeout");
}
}
...
try (Connection connection = ...) {
Request.Builder requestBuilder = Request.builder().setHttpTimeout(httpTimeout);
...
} catch (NumberFormatException ex) {
throw new RegistryAuthenticationFailedException("Non-integer value of jib.httpTimeout");
}
Since all versions of getInteger()
don't throw NumberFormatException
, I guess I need to call parseInt()
after System.getProperty()
.
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.
@coollog and I agreed that we make the code simple and not care about the edge cases too much here. If something goes awry, so be it. Instead, we will guard the errors at the plugin frontends.
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.
Oh let's add a CHANGELOG entry for this.
Part of #582.
Decided to read the system property in
RegistryAuthenticator
andRegistryEndpointCaller
.