Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[net/http] Support timeout of idle "keep-alive" connections in http.Transport #15522

Closed
oxtoacart opened this issue May 3, 2016 · 2 comments
Closed

Comments

@oxtoacart
Copy link
Contributor

Please answer these questions before submitting your issue. Thanks!

  1. What version of Go are you using (go version)?

1.6.2

  1. What operating system and processor architecture are you using (go env)?

darwin/amd64

  1. What did you do?

Run the below test:

package keepalive

import (
    "net/http"
    "testing"
    "time"

    "github.com/getlantern/fdcount"
)

func TestIdle(t *testing.T) {
    _, counter, err := fdcount.Matching("TCP")
    if err != nil {
        t.Fatalf("Error getting fd count: %v", err)
    }

    maxIdleTime := 100 * time.Millisecond
    tr := &http.Transport{
    // MaxIdleTime: maxIdleTime - I'd like to be able to do this
    }
    client := http.Client{
        Transport: tr,
    }
    resp, err := client.Get("https://www.google.com/humans.txt")
    if err != nil {
        t.Fatalf("Unable to make request: %v", err)
    }
    if resp.Body != nil {
        resp.Body.Close()
    }

    time.Sleep(maxIdleTime * 2) // doesn't matter how long I sleep here, connection will never go away
    err = counter.AssertDelta(0)
    if err != nil {
        t.Errorf("Wrong number of TCP file descriptors", err)
    }
}
  1. What did you expect to see?

Test passes.

  1. What did you see instead?
--- FAIL: TestIdle (7.87s)
    keepalive_test.go:34: Wrong number of TCP file descriptors%!(EXTRA *errors.errorString=Unexpected TCP file descriptor count. Expected 0, have 1.

        Removed file descriptors
        -----------------------------


        New file descriptors
        -----------------------------
        keepalive 85989 ox.to.a.cart    5u    IPv4 0x2f354771863b7ca1       0t0       TCP 192.168.29.171:61989->74.125.21.99:443 (ESTABLISHED)
        )
FAIL
FAIL    command-line-arguments  7.892s

I hope to have a patch available for review later today.

@bradfitz
Copy link
Contributor

bradfitz commented May 3, 2016

Already fixed at tip. Dup of #13998. See details there.

@bradfitz bradfitz closed this as completed May 3, 2016
@oxtoacart
Copy link
Contributor Author

Awesome, thanks @bradfitz!

@golang golang locked and limited conversation to collaborators May 3, 2017
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Projects
None yet
Development

No branches or pull requests

3 participants