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
Add timeouts for HTTP clients #165
Conversation
Signed-off-by: Alex Ellis <alexellis2@gmail.com>
Signed-off-by: Alex Ellis <alexellis2@gmail.com>
@@ -18,7 +19,12 @@ func InvokeFunction(gateway string, name string, bytesIn *[]byte, contentType st | |||
gateway = strings.TrimRight(gateway, "/") | |||
|
|||
reader := bytes.NewReader(*bytesIn) | |||
res, err := http.Post(gateway+"/function/"+name, contentType, reader) | |||
var timeout *time.Duration | |||
client := MakeHTTPClient(timeout) |
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.
Nice. Might look a bit cryptic to freshers - worth a comment to explain?
|
||
// MakeHTTPClient makes a HTTP client with good defaults for timeouts. | ||
func MakeHTTPClient(timeout *time.Duration) http.Client { | ||
if timeout != nil { |
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 this meant to be timeout
's only purpose?
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.
How do you mean?
// KeepAlive: 0, | ||
}).DialContext, | ||
// MaxIdleConns: 1, | ||
// DisableKeepAlives: true, |
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.
Prefer not to see commented out code being pushed
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.
Right - I'm not certain about the perfect options yet so may leave in while we test and tune.
proxy/invoke.go
Outdated
var timeout *time.Duration | ||
client := MakeHTTPClient(timeout) | ||
|
||
postRequest, _ := http.NewRequest("POST", gateway+"/function/"+name, reader) |
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 prefer to see use of http method constants in NewRequest
calls. http.MethodPost
for instance. Is this a standard we could adopt?
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.
Yes this can be done. It's mainly a style thing - don't think it blocks the PR. We should do a search across all repos.
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.
Really clean changes. Just a few suggestions/questions.
Signed-off-by: Alex Ellis <alexellis2@gmail.com>
Signed-off-by: Alex Ellis alexellis2@gmail.com
Description
Add timeouts for HTTP clients
Motivation and Context
The configuration of IPv4 / IPv6 and Docker on Linux can be confusing - i.e. #164
This PR should stop "infinite" hang by setting an explicit 3 second timeout.
This timeout is likely to need to be extended for "invoke" or it could break long-running functions.
How Has This Been Tested?
Types of changes
Checklist:
git commit -s