{"action":"created","issue":{"url":"https://api.github.com/repos/golang/go/issues/16005","repository_url":"https://api.github.com/repos/golang/go","labels_url":"https://api.github.com/repos/golang/go/issues/16005/labels{/name}","comments_url":"https://api.github.com/repos/golang/go/issues/16005/comments","events_url":"https://api.github.com/repos/golang/go/issues/16005/events","html_url":"https://github.com/golang/go/issues/16005","id":159164321,"number":16005,"title":"net/http: socket/goroutine leak in http.Transport","user":{"login":"powerman","id":1354301,"avatar_url":"https://avatars.githubusercontent.com/u/1354301?v=3","gravatar_id":"","url":"https://api.github.com/users/powerman","html_url":"https://github.com/powerman","followers_url":"https://api.github.com/users/powerman/followers","following_url":"https://api.github.com/users/powerman/following{/other_user}","gists_url":"https://api.github.com/users/powerman/gists{/gist_id}","starred_url":"https://api.github.com/users/powerman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/powerman/subscriptions","organizations_url":"https://api.github.com/users/powerman/orgs","repos_url":"https://api.github.com/users/powerman/repos","events_url":"https://api.github.com/users/powerman/events{/privacy}","received_events_url":"https://api.github.com/users/powerman/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":{"login":"bradfitz","id":2621,"avatar_url":"https://avatars.githubusercontent.com/u/2621?v=3","gravatar_id":"","url":"https://api.github.com/users/bradfitz","html_url":"https://github.com/bradfitz","followers_url":"https://api.github.com/users/bradfitz/followers","following_url":"https://api.github.com/users/bradfitz/following{/other_user}","gists_url":"https://api.github.com/users/bradfitz/gists{/gist_id}","starred_url":"https://api.github.com/users/bradfitz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bradfitz/subscriptions","organizations_url":"https://api.github.com/users/bradfitz/orgs","repos_url":"https://api.github.com/users/bradfitz/repos","events_url":"https://api.github.com/users/bradfitz/events{/privacy}","received_events_url":"https://api.github.com/users/bradfitz/received_events","type":"User","site_admin":false},"milestone":{"url":"https://api.github.com/repos/golang/go/milestones/38","html_url":"https://github.com/golang/go/milestones/Go1.8","labels_url":"https://api.github.com/repos/golang/go/milestones/38/labels","id":1709363,"number":38,"title":"Go1.8","description":"","creator":{"login":"griesemer","id":8528975,"avatar_url":"https://avatars.githubusercontent.com/u/8528975?v=3","gravatar_id":"","url":"https://api.github.com/users/griesemer","html_url":"https://github.com/griesemer","followers_url":"https://api.github.com/users/griesemer/followers","following_url":"https://api.github.com/users/griesemer/following{/other_user}","gists_url":"https://api.github.com/users/griesemer/gists{/gist_id}","starred_url":"https://api.github.com/users/griesemer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/griesemer/subscriptions","organizations_url":"https://api.github.com/users/griesemer/orgs","repos_url":"https://api.github.com/users/griesemer/repos","events_url":"https://api.github.com/users/griesemer/events{/privacy}","received_events_url":"https://api.github.com/users/griesemer/received_events","type":"User","site_admin":false},"open_issues":273,"closed_issues":23,"state":"open","created_at":"2016-04-15T16:30:23Z","updated_at":"2016-06-08T22:05:58Z","due_on":"2017-02-01T08:00:00Z","closed_at":null},"comments":1,"created_at":"2016-06-08T13:32:15Z","updated_at":"2016-06-08T22:05:58Z","closed_at":"2016-06-08T22:05:58Z","body":"Please answer these questions before submitting your issue. Thanks!\r\n\r\n1. What version of Go are you using (`go version`)?\r\n\r\ngo version go1.6.2 linux/amd64\r\n\r\n2. What operating system and processor architecture are you using (`go env`)?\r\n\r\nGOARCH=\"amd64\"\r\nGOBIN=\"\"\r\nGOEXE=\"\"\r\nGOHOSTARCH=\"amd64\"\r\nGOHOSTOS=\"linux\"\r\nGOOS=\"linux\"\r\nGOPATH=\"/home/powerman/gocode\"\r\nGORACE=\"\"\r\nGOROOT=\"/usr/lib/go\"\r\nGOTOOLDIR=\"/usr/lib/go/pkg/tool/linux_amd64\"\r\nGO15VENDOREXPERIMENT=\"1\"\r\nCC=\"x86_64-pc-linux-gnu-gcc\"\r\nGOGCCFLAGS=\"-fPIC -m64 -pthread -fmessage-length=0\"\r\nCXX=\"x86_64-pc-linux-gnu-g++\"\r\nCGO_ENABLED=\"1\"\r\n\r\n\r\n3. What did you do?\r\n\r\n```go\r\npackage main\r\n\r\nimport (\r\n\t\"fmt\"\r\n\t\"io\"\r\n\t\"io/ioutil\"\r\n\t\"net/http\"\r\n\t\"runtime\"\r\n\t\"time\"\r\n)\r\n\r\nfunc main() {\r\n\tfor {\r\n\t\tc := &http.Client{\r\n\t\t\tTransport: &http.Transport{\r\n\t\t\t\tExpectContinueTimeout: 1 * time.Second, // A\r\n\t\t\t},\r\n\t\t}\r\n\t\tresp, err := c.Get(\"http://google.com\")\r\n\t\tif resp != nil {\r\n\t\t\tio.Copy(ioutil.Discard, resp.Body) // B\r\n\t\t\tresp.Body.Close()                  // B\r\n\t\t}\r\n\t\tfmt.Printf(\"resp=%t, err=%v\\n\", resp != nil, err)\r\n\t\ttime.Sleep(time.Second)\r\n\t\tc.Transport.(*http.Transport).CloseIdleConnections() // C\r\n\t\truntime.SetFinalizer(c, func(interface{}) { fmt.Println(\"--- http.Client GONE\") })\r\n\t\truntime.SetFinalizer(c.Transport, func(interface{}) { fmt.Println(\"--- http.Transport GONE\") })\r\n\t\truntime.GC()\r\n\t}\r\n}\r\n```\r\n\r\n4. What did you expect to see?\r\n\r\n```\r\nresp=true, err=<nil>\r\n--- http.Client GONE\r\nresp=true, err=<nil>\r\n--- http.Client GONE\r\n--- http.Transport GONE\r\nresp=true, err=<nil>\r\n--- http.Client GONE\r\n--- http.Transport GONE\r\nresp=true, err=<nil>\r\n--- http.Client GONE\r\n--- http.Transport GONE\r\nresp=true, err=<nil>\r\n^Csignal: interrupt\r\n```\r\n\r\n5. What did you see instead?\r\n\r\nProvided program works correctly and gives output shown above. But if we'll comment any of lines marked `// A` or `// B` or `// C` then http.Transport won't be garbage-collected anymore and output became:\r\n```\r\nresp=true, err=<nil>\r\n--- http.Client GONE\r\nresp=true, err=<nil>\r\n--- http.Client GONE\r\nresp=true, err=<nil>\r\n--- http.Client GONE\r\nresp=true, err=<nil>\r\n--- http.Client GONE\r\nresp=true, err=<nil>\r\n^Csignal: interrupt\r\n```\r\n\r\nI know it's recommended to share same http.Client for all application, but I'm developing load-testing application which simulate thousands of independent clients and thus require own simulated client to use own http.Client and own http.Transport objects to behave more like real independent clients."},"comment":{"url":"https://api.github.com/repos/golang/go/issues/comments/224744295","html_url":"https://github.com/golang/go/issues/16005#issuecomment-224744295","issue_url":"https://api.github.com/repos/golang/go/issues/16005","id":224744295,"user":{"login":"adg","id":8446613,"avatar_url":"https://avatars.githubusercontent.com/u/8446613?v=3","gravatar_id":"","url":"https://api.github.com/users/adg","html_url":"https://github.com/adg","followers_url":"https://api.github.com/users/adg/followers","following_url":"https://api.github.com/users/adg/following{/other_user}","gists_url":"https://api.github.com/users/adg/gists{/gist_id}","starred_url":"https://api.github.com/users/adg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adg/subscriptions","organizations_url":"https://api.github.com/users/adg/orgs","repos_url":"https://api.github.com/users/adg/repos","events_url":"https://api.github.com/users/adg/events{/privacy}","received_events_url":"https://api.github.com/users/adg/received_events","type":"User","site_admin":false},"created_at":"2016-06-08T22:05:58Z","updated_at":"2016-06-08T22:05:58Z","body":"I'm not sure what you expect to happen here. All the code is working exactly as documented. In particular, you must always Close the response body when using http.Client.\r\n\r\nYou can turn off keepalives entirely in your custom [http.Transport](https://golang.org/pkg/net/http/#Transport) if you like. There are also configuration knobs on Client that you may wish to turn.\r\n "}}
{"actor":{"display_login":"adg"}}