You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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
.The text was updated successfully, but these errors were encountered: