-
Notifications
You must be signed in to change notification settings - Fork 295
Adding default timeout to Snap REST client #1487
Conversation
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.
LGTM
IdleConnTimeout: time.Second, | ||
TLSClientConfig: &tls.Config{InsecureSkipVerify: false}, | ||
IdleConnTimeout: time.Second, | ||
ResponseHeaderTimeout: 10 * time.Second, |
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.
Does it make sense to add this as a const somewhere so that it can be edited in one place or potentially modified via config in the future?
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.
Constant created.
|
||
go http.ListenAndServe("127.0.0.1:65000", timeoutHandler{}) | ||
c, err = New("http://127.0.0.1:65000", "", true) | ||
FocusConvey("Client should timeout", t, func() { |
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.
What's the advantage of FocusConvey here?
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.
None. I have not cleaned the code up after writing a test, apparently. Removed.
Since the metaOpt is defined in the client package it has access to the clients unexported http property, unless I'm misunderstanding something. I also think we can use the http.Client's Timeout property rather than the transports since the transport can be shared among clients and we don't want to enforce identical timeouts (necessarily) across all clients. Something like this inside client.go: func Timeout (t time.Duration) metaOp {
return func(c *Client) {
c.http.Timeout = t
}
} Then you would call into the New function with: c, _ := client.New("address", "", true, client.Timeout(10*time.Second)) Does this seem like it would solve your problem @iwankgb? |
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.
Just leaving this so it's not merged before you have a chance to respond to my comment re: using a metaOpt.
I was originally thinking about using |
@iwankgb: Yes I think that's a little cleaner than the my original thought about just having the const. I also like the idea of using the http.Client timeout instead of the Transport since modifying the Transport would affect all clients. |
OK :) |
LGTM @iwankgb. Could you squash to a single commit so it can be merged? |
2752f9c
to
3ab8439
Compare
3ab8439
to
13f1b6d
Compare
Thanks a lot, @IRCody :) |
Fixes issue of infinitely blocking HTTP connections (mitigates #1482 and similar issues).
Summary of changes:
Testing done:
It does not seem to be possible to use
opts
parameter ofclient.New() as client's
http` property is unexported and therefore unavailble from another packages.@intelsdi-x/snap-maintainers