I'm having problems with urlfetch timeouts in Google App Engine in Go. Perhaps the application does not want to use a longer timeout than about 5 seconds (it ignores a longer timeout and expires after its own time).
My code is:
var TimeoutDuration time.Duration = time.Second*30 func Call(c appengine.Context, address string, allowInvalidServerCertificate bool, method string, id interface{}, params []interface{})(map[string]interface{}, error){ data, err := json.Marshal(map[string]interface{}{ "method": method, "id": id, "params": params, }) if err != nil { return nil, err } req, err:=http.NewRequest("POST", address, strings.NewReader(string(data))) if err!=nil{ return nil, err } tr := &urlfetch.Transport{Context: c, Deadline: TimeoutDuration, AllowInvalidServerCertificate: allowInvalidServerCertificate} resp, err:=tr.RoundTrip(req) if err != nil { return nil, err } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { return nil, err } result := make(map[string]interface{}) err = json.Unmarshal(body, &result) if err != nil { return nil, err } return result, nil }
No matter what I try to set the TimeoutDuration , the application expires after 5 seconds. How to prevent this? Did I make a mistake in my code?
source share