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 when querying GetElapsedTime() #50

Merged
merged 1 commit into from
Sep 21, 2017

Conversation

vincentbernat
Copy link
Contributor

ExponentialBackOff.GetElapsedTime() reads start time which is reset
by ExponentialBackOff.Reset() which is called by run(), executed
in a goroutine. This creates a data race just by using:

b := NewExponentialBackOff()
ticker := backoff.NewTicker(b)
b.GetElapsedTime()

This commit solves this by resetting the backoff timer outside the
goroutine. The ticker test has been updated for this particular data
race.

`ExponentialBackOff.GetElapsedTime()` reads start time which is reset
by `ExponentialBackOff.Reset()` which is called by `run()`, executed
in a goroutine. This creates a data race just by using:

```go
b := NewExponentialBackOff()
ticker := backoff.NewTicker(b)
b.GetElapsedTime()
```

This commit solves this by resetting the backoff timer outside the
goroutine. The ticker test has been updated for this particular data
race.
@coveralls
Copy link

coveralls commented Sep 19, 2017

Coverage Status

Coverage remained the same at 83.516% when pulling ff874c0 on vincentbernat:fix/datarace-reset into 80e08cb on cenkalti:master.

@cenkalti cenkalti merged commit 61ba96c into cenkalti:master Sep 21, 2017
@cenkalti
Copy link
Owner

@vincentbernat Thank you!

Does this PR also fix #47?

@vincentbernat
Copy link
Contributor Author

This is a separate issue. I'll comment on it.

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.

None yet

3 participants