Skip to content
This repository has been archived by the owner on Nov 8, 2022. It is now read-only.

Adding default timeout to Snap REST client #1487

Merged
merged 1 commit into from
Jan 26, 2017

Conversation

iwankgb
Copy link
Contributor

@iwankgb iwankgb commented Jan 21, 2017

Fixes issue of infinitely blocking HTTP connections (mitigates #1482 and similar issues).

Summary of changes:

  • added default timeout of 10 seconds to secure and insecure transports

Testing done:

  • added a functional test for the timeout feature

It does not seem to be possible to use opts parameter of client.New() as client's http` property is unexported and therefore unavailble from another packages.

@intelsdi-x/snap-maintainers

Copy link
Collaborator

@marcin-krolik marcin-krolik left a 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,
Copy link
Contributor

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?

Copy link
Contributor Author

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() {
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@IRCody
Copy link
Contributor

IRCody commented Jan 24, 2017

It does not seem to be possible to use opts parameter of client.New() as client'shttp` property is unexported and therefore unavailble from another packages.

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?

Copy link
Contributor

@IRCody IRCody left a 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.

@iwankgb
Copy link
Contributor Author

iwankgb commented Jan 25, 2017

I was originally thinking about using metaOp in our application code but adding such a function in client package would solve the issue indeed. Do you want to have such a function implemented and default timeout setting removed?

@IRCody
Copy link
Contributor

IRCody commented Jan 25, 2017

@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.

@iwankgb
Copy link
Contributor Author

iwankgb commented Jan 25, 2017

OK :)

@IRCody
Copy link
Contributor

IRCody commented Jan 25, 2017

LGTM @iwankgb. Could you squash to a single commit so it can be merged?

@jcooklin jcooklin merged commit da6ad2e into intelsdi-x:master Jan 26, 2017
@iwankgb
Copy link
Contributor Author

iwankgb commented Jan 26, 2017

Thanks a lot, @IRCody :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants