Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

method executed within hystrix behaving weiredly #116

Open
Kaustavd opened this issue Jul 23, 2021 · 0 comments
Open

method executed within hystrix behaving weiredly #116

Kaustavd opened this issue Jul 23, 2021 · 0 comments

Comments

@Kaustavd
Copy link

Kaustavd commented Jul 23, 2021

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

Screenshot 2021-07-23 at 3 53 44 PM

Second Invoction Result

Screenshot 2021-07-23 at 3 53 56 PM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant