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

Locking algorithm is not concurrency safe #9

Open
martinxsliu opened this issue Apr 18, 2024 · 0 comments
Open

Locking algorithm is not concurrency safe #9

martinxsliu opened this issue Apr 18, 2024 · 0 comments

Comments

@martinxsliu
Copy link

Hi team, firstly thanks for creating this useful library!

I discovered a critical issue with the locking mechanism not being concurrency safe when you have multiple worker instances running this rate limiter. The issue is that using PEXPIRE will always extend the TTL of the key. So after the key is initially set by the first drain by the first instance, another instance will attempt to lock within the drain interval of the bucket type. It will fail, but it will inadvertently extend the TTL of the locked key. There is a small amount of wiggle room because of the 10ms of buffer, but most likely what will happen is that the instances will keep extending the TTL and blocking each other from running and hence the bucket will never get drained.

I think this can be fixed by using SET with NX and PX options or using a package like redlock.

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

No branches or pull requests

1 participant