I have a program that periodically does a HTTP GET. The simplified codes looks like that.
``` package main import ( "log" "net/http" "testing" "time" ) func TestPlay(t *testing.T) { for { log.Println("starting request") // If I use this, the test will hang forever! // rsp, err := http.Get("http://google.com") client := http.Client{Timeout: time.Second * 3} rsp, err := client.Get("http://google.com") if err != nil { t.Fatal(err) } if err = rsp.Body.Close(); err != nil { t.Fatal(err) } log.Println("request finished") log.Println("sleeping...") time.Sleep(time.Second * 1) } } ``` Problem is when a user connects to a VPN network, the request will fails with following error. ``` main_test.go:17: Get http://google.com: net/http: request canceled (Client.Timeout exceeded while awaiting headers) ``` And if I didn't set timeout in http.Client, it will hang forever! So my questions are: - is this normal, expected behavior of http.Client? - what is the best way to handle this? beside just retry the request? -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.