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

Fix data race in hystrix client #67

Closed

Conversation

ardhitama
Copy link

This fix #63

@coveralls
Copy link

Coverage Status

Coverage remained the same at 87.234% when pulling 3aad9e6 on ardhitama:fix-data-race-in-hystrix-client into ef69e0b on gojektech:master.

@@ -179,7 +179,7 @@ func (hhc *Client) Do(request *http.Request) (*http.Response, error) {
}

err = hystrix.Do(hhc.hystrixCommandName, func() error {
response, err = hhc.client.Do(request)
resp, err := hhc.client.Do(request)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you elaborate on this fix plz ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are two possible source of errors, hystrix and net/http. If both having the same timeout value, the err will be in race, as it can override one another.

Copy link

@unmultimedio unmultimedio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was having the same issue in a project of mine, in which I do:

for _, someURL := range someURLs {
  resp, err := customClient.Get(ctx, someURL, http.Header{})
  if err != nil {
    continue
  }
  defer log.CloseOrLog(resp.Body)

  body, err = ioutil.ReadAll(resp.Body)
  if err != nil {
    continue
  }
  myVar += string(body)
}

And I had the race condition like:

==================
WARNING: DATA RACE
Write at 0x00c000176040 by goroutine 37:
  repos_host/team/project/vendor/github.com/gojektech/heimdall/hystrix.(*Client).Do()
      /GO_PATH/go/src/repos_host/team/project/vendor/github.com/gojektech/heimdall/hystrix/hystrix_client.go:181 +0x3de
  Some trace up to a line of code in which we do a `hystrixClient.Do()` call...

  testing.tRunner()
      /usr/local/Cellar/go/1.12.7/libexec/src/testing/testing.go:865 +0x163

After trying with this branch, that race condition didn't happen anymore. cc @senekis

@@ -407,25 +407,10 @@ func BenchmarkHystrixHTTPClientRetriesPostOnFailure(b *testing.B) {
}
}

func TestHystrixHTTPClientReturnsFallbackFailureWithoutFallBackFunction(t *testing.T) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you deleted this test?

@@ -518,6 +503,40 @@ func TestCustomHystrixHTTPClientDoSuccess(t *testing.T) {
assert.Equal(t, "{ \"response\": \"ok\" }", string(body))
}

func TestHystrixHTTPClientGetReturnedURLTimeout(t *testing.T) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have tested this branch and the tests pass successfully

@unmultimedio
Copy link

Hello, is there any progress on this? Is this repo still being maintained?

@rShetty
Copy link
Contributor

rShetty commented Jun 1, 2020

@ardhitama Can you help resolve conflicts if this is still relevant?

@ardhitama
Copy link
Author

fixed in latest master

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

Successfully merging this pull request may close these issues.

Data race found
4 participants