method executed within hystrix behaving weiredly
Kaustavd opened this issue · comments
Kaustavd commented
Hi,
Sample code:
payload io.Reader) (bool, int) {
//build request
request, err := http.NewRequest(method, url, payload)
if err != nil {
log.Printf("failed in request build %s %s \n", url, err.Error())
return false, 0
}
//make request
response, err := h.HttpExecute(request)
if err != nil {
log.Println("HttpCommand=Error URL=", url, " Error=", err)
return false, 0
} else {
log.Println("HttpCommand=Success response=", response, " error=", err)
io.Copy(ioutil.Discard, response.Body)
defer response.Body.Close()
return true, response.StatusCode
}
}
func (h *HTTPSink) HttpExecute(input *http.Request) (response *http.Response, err error){
if err := hystrix.Do("http", func() (err error) {
response, err = h.client.Do(input)
return err
}, nil); err != nil {
return nil, err
}
return response, nil
}
In the above code response, err := h.HttpExecute(request) is behaving in non deterministic fashion. While running in debug mode err is coming as nil although destination server failed (4xx) but while executing the same line second time getting correct error
First invocation result
Second Invoction Result