Created
September 16, 2016 18:55
-
-
Save sajal/cada559fea365fc2f7468a6e40e82e4b to your computer and use it in GitHub Desktop.
reproduction for Go issue #16808
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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