Skip to content

method executed within hystrix behaving weiredly #116

@Kaustavd

Description

@Kaustavd

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions