Skip to content

Fix Redis rate limiter TTL race condition - #2463

Open
tanishka-kuwar wants to merge 1 commit into
utksh1:mainfrom
tanishka-kuwar:fix/1759-redis-rate-limit-race
Open

Fix Redis rate limiter TTL race condition#2463
tanishka-kuwar wants to merge 1 commit into
utksh1:mainfrom
tanishka-kuwar:fix/1759-redis-rate-limit-race

Conversation

@tanishka-kuwar

Copy link
Copy Markdown
Contributor

🔗 Related Issue

Closes #1759


📝 Summary of Changes

  • Updated the Redis-backed rate limiter to use EXPIRE(..., nx=True) for both minute and hour buckets.
  • Prevents resetting the TTL on every request.
  • Preserves the original expiration while still restoring it if a key unexpectedly has no TTL.

🏷️ Type of Change

  • 🐛 Bug fix
  • ✨ New feature
  • ♻️ Refactor
  • 📝 Documentation update
  • 🎨 UI / Style change
  • 🔧 Chore

🧪 Testing

Ran:

python -m pytest testing/backend/unit -k rate_limiter -v

Result:

  • ✅ 17 rate limiter tests passed.

✅ Checklist

  • No merge conflicts
  • Changes follow the project guidelines
  • Related issue linked
  • Changes tested locally

@tanishka-kuwar

Copy link
Copy Markdown
Contributor Author

Hi @utksh1,

The backend rate limiter change passes all relevant local tests.

The failing CI appears to be unrelated to this PR. The failure is in the frontend npm audit step due to an existing high-severity vulnerability in the undici dependency:

GHSA-4cwx-7wf7-3272

Since this PR only modifies backend/secuscan/rate_limiter.py, could you please rerun or advise if this dependency issue is expected?

Thank you

@utksh1 utksh1 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good fix for Redis TTL race condition using nx=True. Backend-only change; frontend check failures are unrelated.

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

Successfully merging this pull request may close these issues.

[#13] Redis INCR/EXPIRE race can permanently block an IP

2 participants