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

Conversation

chrisst
Copy link
Contributor

@chrisst chrisst commented Dec 14, 2018


[all]

Make the default timout 5 minutes when timeout is 0

[terraform]

[terraform-beta]

[ansible]

[inspec]

@modular-magician
Copy link
Collaborator

I am a robot that works on MagicModules PRs!

I built this PR into one or more PRs on other repositories, and when those are closed, this PR will also be merged and closed.
depends: hashicorp/terraform-provider-google-beta#227
depends: hashicorp/terraform-provider-google#2667

@@ -41,6 +41,10 @@ func sendRequestWithTimeout(config *Config, method, rawurl string, body map[stri
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.

@modular-magician
Copy link
Collaborator

I am (still) a robot that works on MagicModules PRs!

I just wanted to let you know that your changes (as of commit 9e08a51) have been included in your existing downstream PRs.

third_party/terraform/utils/transport.go Outdated Show resolved Hide resolved
@@ -41,6 +41,10 @@ func sendRequestWithTimeout(config *Config, method, rawurl string, body map[stri
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.

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

@modular-magician
Copy link
Collaborator

I am (still) a robot that works on MagicModules PRs!

I just wanted to let you know that your changes (as of commit 0a211a8) have been included in your existing downstream PRs.

@modular-magician modular-magician merged commit f4c904d into GoogleCloudPlatform:master Dec 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants