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

resolve BasicTokenBucket thread-safe issue #2327

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Lawliet828
Copy link

@Lawliet828 Lawliet828 commented Oct 25, 2024

Description

if rate_ and burstSize_ are not atomic, the function consume, consumeOrDrain, available, balance, rate, burst of BasicTokenBucket are not thread-safe.

thread 1 : reset -> write rate_ and burstSize_
thread 2 : consume -> read rate_ and burstSize_

If there are two threads, one executing consume and the other executing reset simultaneously, it will cause the values of rate_ and burstSize_ to be indeterminate, potentially being neither the new nor the old values.

the reset interface is provided, as long as two threads access rate_ and burstSize_ simultaneously, and at least one of them is a modification operation, it will lead to thread safety issues.

Issue

#2328

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants