fix: make rate limiter atomic#197
Conversation
|
@GhanshyamJha05 is attempting to deploy a commit to the codersogs-3057's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
Hi @Ayush-Patel-56 , I’ve opened this PR for #134. I fixed the non-atomic rate limiter flow by moving the counter update into an atomic cache backend operation while keeping the existing Verified locally with typecheck, lint, prettier check, and the full test suite. All 44 test files / 380 tests passed. |
Siddhartha-singh01
left a comment
There was a problem hiding this comment.
@GhanshyamJha05 Just check the code base I think there is some noise in the code
2ddf824 to
8a4f020
Compare
|
Thanks for pointing that out. I checked the codebase again and reduced the noisy part of the implementation. The earlier version added a larger Lua-script based path in I also rebased the branch on latest
All 45 test files / 381 tests passed. |
Summary
Fixes a concurrency bug in the fixed-window rate limiter where parallel requests could bypass the limit because the counter update used a non-atomic
cacheGet -> compare -> cacheSetflow.This PR moves the rate-limit counter update into an atomic cache backend operation so concurrent requests for the same key cannot all read the same stale counter.
Type of Change
Related Issue
Closes #134
What was changed?
rateLimit()read/check/write flow withcacheRateLimitHit().rateLimit()API and response shape unchanged.Promise.all(...)to verify that only the configured limit is allowed during a burst.Screenshots
Not applicable. This is a backend/security fix with no UI changes.
Checklist
npm run dev)