2016. november 17., csütörtök 15:52:54 UTC+1 időpontban Diep Pham a 
következőt írta:
>
> 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? 
>


Most probably the network is misconfigured, or just does not allow access 
to http://google.com through the VPN. 
Either allow accessing google.com through the VPN, or configure the network 
to only "use the resources" on the VPN, do not forward all traffic through 
it.

This is not a Go problem, though.

-- 
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.

Reply via email to