Skip to content

fix: make rate limiter fail closed when Redis is unreachable - #11

Merged
Emp1500 merged 1 commit into
mainfrom
fix/rate-limit-fail-closed
Jul 18, 2026
Merged

fix: make rate limiter fail closed when Redis is unreachable#11
Emp1500 merged 1 commit into
mainfrom
fix/rate-limit-fail-closed

Conversation

@Emp1500

@Emp1500 Emp1500 commented Jul 18, 2026

Copy link
Copy Markdown
Owner

Summary

The Upstash rate limiter failed open: on its default 5s timeout it resolves { success: true, reason: 'timeout' }, so a Redis outage or induced latency let requests bypass saveLimit/shareLimit entirely. This change makes the limiter fail closed, the correct default for an abuse-prevention control.

Changes

  • Set an explicit timeout: 1000 on the limiters (was defaulting to 5s).
  • checkRateLimit now denies on Upstash's timeout response and on any thrown
    error, so limits cannot be bypassed by inducing Redis latency.
  • Removed the unused globalLimit export.

Trade-off

During a full Redis outage, save/share return 429 rather than passing through. Impact is bounded to the outage window.

Testing

Added __tests__/rate-limit.test.ts (timeout, error, allow, deny). Full suite passing: 12 suites, 65 tests. Route handlers unchanged — the { success, retryAfter } contract is preserved.

Upstash Ratelimit's default 5s timeout resolves { success: true,
reason: 'timeout' } when Redis is unreachable, silently bypassing rate
limits. Add an explicit 1s timeout and have checkRateLimit translate the
timeout response (and any thrown error) into a deny, so limits can't be
bypassed by inducing Redis latency. Also drop the unused globalLimit.
@vercel

vercel Bot commented Jul 18, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
code2flow Ready Ready Preview, Comment Jul 18, 2026 11:05am

@Emp1500
Emp1500 merged commit e42489f into main Jul 18, 2026
3 checks passed
@Emp1500
Emp1500 deleted the fix/rate-limit-fail-closed branch July 18, 2026 11:18
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.

1 participant