-
Notifications
You must be signed in to change notification settings - Fork 188
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 pointer issue #839
Fix pointer issue #839
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RIP mutation roulette. Nice fix. LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't fully understand how this change will fix the problem. A better description in the PR with an example would be helpful for me.
|
||
d.logger.Debug("Bucket level updated", "key", params.RequesterID, "name", params.RequesterName, "prevLevel", prevLevel, "level", bucketParams.BucketLevels[i], "size", size, "interval", interval, "deduction", deduction, "allowed", allowed) | ||
d.logger.Debug("Bucket level updated", "key", params.RequesterID, "name", params.RequesterName, "prevLevel", bucketParams.BucketLevels[i], "level", bucketLevels[i], "size", size, "interval", interval, "deduction", deduction, "allowed", allowed) | ||
|
||
// Update metrics only if the requester name is provided. We're making |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we update the metric to use bucketLevels[i]
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
I updated the PR description with a better explanation! |
Why are these changes needed?
Addresses a pointer issue in the below portion of the rate limiter implementation:
This code returns the
bucketParams
struct, which is then push back to the rate limiter's KV store when the call is allowed.The problem here is that
bucketParams.BucketLevels
is an array slice and the KV store is an in-memory LRU cache. Even thoughbucketParams
is a copy of the object stored in the KV store, both objects reference the same slice. The code here will directly update the slice, so that whenallowed
is false, the bucket level is inadvertently updated.Checks