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: remove data race when resetting ticker #161

Merged
merged 1 commit into from
Oct 23, 2023
Merged

Conversation

ericwenn
Copy link
Member

Currently there is a data race in the Ticker that is triggered when
Ticker.Reset and Ticker.IsDurationReached are called concurrently.
IsDurationReached is called by the clock as part of Clock.SetTimestamp and
Ticker.Reset is called by user-code.

This commit fixes the data race by protecting duration field of Ticker
with the mutex. This also forces inlining of some calls in both methods
as the called methods will also attempt to lock the mutex.

Currently there is a data race in the Ticker that is triggered when
Ticker.Reset and Ticker.IsDurationReached are called concurrently.
IsDurationReached is called by the clock as part of Clock.SetTimestamp and
Ticker.Reset is called by user-code.

This commit fixes the data race by protecting `duration` field of Ticker
with the mutex. This also forces inlining of some calls in both methods
as the called methods will also attempt to lock the mutex.
@ericwenn ericwenn requested a review from a team as a code owner October 20, 2023 17:32
Copy link
Member

@erikbohnsack erikbohnsack left a comment

Choose a reason for hiding this comment

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

Good stuff!

@ericwenn ericwenn merged commit dbd5807 into master Oct 23, 2023
1 check passed
@ericwenn ericwenn deleted the race-ticker-reset branch October 23, 2023 07:24
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.

2 participants