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

consumer: re-use http client or disable keep alives #169

Closed
zalecn opened this issue Feb 4, 2016 · 2 comments
Closed

consumer: re-use http client or disable keep alives #169

zalecn opened this issue Feb 4, 2016 · 2 comments
Labels

Comments

@zalecn
Copy link

zalecn commented Feb 4, 2016

apiRequestNegotiateV1:

httpclient := &http.Client{Transport: newDeadlineTransport(2 * time.Second)}

newDeadlineTransport:

func newDeadlineTransport(timeout time.Duration) *http.Transport {
    transport := &http.Transport{
        Dial: func(netw, addr string) (net.Conn, error) {
            c, err := net.DialTimeout(netw, addr, timeout)
            if err != nil {
                return nil, err
            }
            return &deadlinedConn{timeout, c}, nil
        },
    }
    return transport
}

net/http doesn't immediately close the connection if the transport DisableKeepAlives no set true.
if you want to reuse the connection, must keep the same transport object, because golang put idle connection in the transport object.

@mreiferson
Copy link
Member

mreiferson commented Feb 4, 2016

@zalecn interesting, thanks for the report!

@mreiferson mreiferson added the bug label Feb 4, 2016
@mreiferson mreiferson changed the title a lot unclosed http client , when set small LookupdPollInterval consumer: re-use http client or disable keep alives Feb 4, 2016
@mreiferson mreiferson added chore and removed bug labels Apr 16, 2017
@mreiferson
Copy link
Member

fixed in #209

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

No branches or pull requests

2 participants