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

Make the default timout 5 minutes when timeout is 0 #1056

Merged
merged 4 commits into from
Dec 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build/terraform
2 changes: 1 addition & 1 deletion build/terraform-beta
6 changes: 5 additions & 1 deletion third_party/terraform/utils/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,18 @@ func isEmptyValue(v reflect.Value) bool {
}

func sendRequest(config *Config, method, rawurl string, body map[string]interface{}) (map[string]interface{}, error) {
return sendRequestWithTimeout(config, method, rawurl, body, 0)
return sendRequestWithTimeout(config, method, rawurl, body, 5*time.Minute)
}

func sendRequestWithTimeout(config *Config, method, rawurl string, body map[string]interface{}, timeout time.Duration) (map[string]interface{}, error) {
reqHeaders := make(http.Header)
reqHeaders.Set("User-Agent", config.userAgent)
reqHeaders.Set("Content-Type", "application/json")

if timeout == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not just have sendRequest send 5 instead of 0?

Copy link
Contributor Author

@chrisst chrisst Dec 14, 2018

Choose a reason for hiding this comment

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

I had considered that, but if somebody called sendRequestWithTimeout and passed in a 0 timeout (the nil value for timeout) then it will timeout immediately which doesn't feel like a good behavior for handling a nil value. I would have preferred if a nil value caused there to be no timeout at all but that would have made the method a bit more complex so I took this middle route.

I don't feel super strongly about any of the options so let me know if you have a preference.

Copy link
Member

Choose a reason for hiding this comment

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

Drive-by but personally I would prefer passing in the default value in sendRequest instead of replacing actual timeout values of 0 with that default

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Out of curiosity, what's your opinion on expected behavior when passing in a nil value into the callWithTimeout method?

Copy link
Member

Choose a reason for hiding this comment

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

Either an explicit error or something terrible happening! I could also see one of 0 or nil meaning no timeout at all if time.Duration doesn't express that in another way.

Copy link
Contributor

Choose a reason for hiding this comment

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

wouldn't that be a compile-time error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Passing actual nil would be compile time, but it's recommended that you code should handle zero value inputs in a responsible manner. So I would think that if you passed in a zero value for a timeout that the code would handle it with no timeout, since a timeout of 0 isn't really a thing.
Kind of like how methods that are on pointer receivers shouldn't throw errors or panic when called with a nil receiver.

Copy link
Contributor

Choose a reason for hiding this comment

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

That makes sense. I don't think there's a way to do infinity, but you can certainly just do a very large number.

timeout = time.Duration(1) * time.Hour
}

var res *http.Response
err := retryTimeDuration(
func() error {
Expand Down