Skip to content

Instantly share code, notes, and snippets.

@sajal
Created September 16, 2016 18:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sajal/cada559fea365fc2f7468a6e40e82e4b to your computer and use it in GitHub Desktop.
Save sajal/cada559fea365fc2f7468a6e40e82e4b to your computer and use it in GitHub Desktop.
reproduction for Go issue #16808
package main
import (
"log"
"net"
"net/http"
"os"
"os/exec"
"strconv"
"time"
)
func access(url string) {
transport := &http.Transport{
Proxy: http.ProxyFromEnvironment,
DialContext: (&net.Dialer{
Timeout: time.Second * 15, //DNS + Connect
KeepAlive: time.Second * 30,
}).DialContext,
MaxIdleConns: 100,
IdleConnTimeout: 5 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
}
client := http.Client{
Transport: transport,
CheckRedirect: func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse
}, //Since we now use high-level client we must stop redirects.
}
req, err := http.NewRequest("GET", url, nil)
if err != nil {
log.Fatal(err)
}
resp, err := client.Do(req)
if err != nil {
log.Fatal(err)
}
log.Println(resp.Proto)
resp.Body.Close()
}
func lsof() {
pid := os.Getpid()
cmd := exec.Command("lsof", "-p", strconv.Itoa(pid))
out, err := cmd.Output()
if err != nil {
log.Fatal(err)
}
log.Println(string(out))
}
func main() {
access(os.Args[1])
lsof()
time.Sleep(6 * time.Second)
lsof()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment