SlidingTimeWindowMovingAverages data race
carterkozak opened this issue · 1 comments
I believe there's a race condition in SlidingTimeWindowMovingAverages
where concurrent accessors may retain a stale currentBucketIndex
value, and update unexpected buckets.
Callers call tickIfNecessary
, then update
(or access):
In heavily concurrent environments (e.g. webservers), a compare-and-swap failure within tickIfNecessary
(or even another thread completing the tick operation first, not necessarily in parallel) will lead to stale currentBucketIndex
values depending on how the methods are optimized at runtime.
currentBucketIndex
(and likely a couple other related fields) could be updated with the volatile
modifier to avoid stale reads, however this comes with a minor performance penalty as the memory must be read each time it's accessed. It's unclear if this is an intentional tradeoff.
This issue is stale because it has been open 180 days with no activity. Remove the "stale" label or comment or this will be closed in 14 days.