GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat(rateLimit): `dryRun`, `onLimited`, and no `rateLimitRes` on the error by fratzinger · Pull Request #84 · feathersjs/feathers-utils

Conversation

@fratzinger

@fratzinger fratzinger commented Nov 6, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Summary

A limit set too tight rejects real traffic. dryRun lets a limit run in production first and only report, before it rejects anything:

 consume(key, points)
   under the limit → headers, next()
   over the limit
+    onLimited(info, context)          // every call over the limit
+    dryRun → headers, no Retry-After, next()
     else   → headers + Retry-After, throw TooManyRequests
  • dryRun?: boolean | PredicateFn — default false. A predicate decides per call, e.g. to enforce for some callers first. The call still consumes its points, so the headers and context.params.rateLimit show where it stands.
  • onLimited?: (info, context) => Promisable<void> — every call over the limit, rejected or let through; the hook for a log line or a metric. It gets the same RateLimitInfo as the headers.
  • A store that fails is no call over the limit: it still rejects, dryRun or not, and doesn't reach onLimited.
  • Breaking: the rejection no longer carries data.rateLimitRes (the TODO(next major)). An error's data goes to the client, and on a shared bucket the limiter's points tell every caller how much everyone else calls. data is { retryAfter, headers? }; the limiter's answer — or a failing store's error — stays on context.params.rateLimit.
 throw new TooManyRequests('Too many requests', {
-  rateLimitRes: res,
   retryAfter,
   ...(values ? { headers: values } : {}),
 })

Evidence

dryRun: true, 1 point / 60 s
  1st call → passes, onLimited not called
  2nd call → next() runs, RateLimit headers without Retry-After, consumedPoints 2,
             onLimited({ limit: 1, remaining: 0, reset: 60, window: 60, limited: true }, context)
dryRun: context => context.params.trial
  over the limit with trial → passes; without → TooManyRequests
onLimited without dryRun → called once, then TooManyRequests
rejection → error.data equals { retryAfter, headers } exactly; consumedPoints on context.params.rateLimit
failing store with dryRun → TooManyRequests without data, the store's error on context.params.rateLimit,
                             onLimited not called

pnpm test: 158 files, 2009 passed, no lint errors, no type errors.

Merge Danger

Door: two-way

dryRun and onLimited are off by default. Dropping rateLimitRes is a breaking change for anyone reading error.data.rateLimitRes — a major, or a minor if that's judged rare enough.

Blast Radius: small

Clients lose the limiter's raw points in the error body; retryAfter and the headers stay. Server code reading error.data.rateLimitRes reads context.params.rateLimit instead.

🤖 Generated with Claude Code

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@fratzinger @claude
feat(rateLimit): dryRun and onLimited
6fbf0fa
- `dryRun` (default `false`, or a predicate per call) lets a call over the
  limit through: it still consumes its points and gets the headers, but no
  `Retry-After` and no `TooManyRequests` - to measure a limit before
  enforcing it.
- `onLimited(info, context)` is called for every call over the limit,
  rejected or let through, e.g. to log or count it. A failing store is no
  call over the limit and still rejects.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 6, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Deploying feathers-utils with  Cloudflare Pages  Cloudflare Pages

Latest commit: 66662ea
Status: ✅  Deploy successful!
Preview URL: https://661c52b0.feathers-utils.pages.dev
Branch Preview URL: https://feat-rate-limit-dry-run.feathers-utils.pages.dev

View logs

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@fratzinger @claude
feat(rateLimit)!: drop rateLimitRes from the error
66662ea
An error's `data` goes to the client, and on a shared bucket the
limiter's points tell every caller how much everyone else calls. The
rejection carries `retryAfter` and `headers` only; the limiter's answer -
or a failing store's error - stays on `context.params.rateLimit`.

BREAKING CHANGE: `TooManyRequests.data.rateLimitRes` is gone; read
`context.params.rateLimit` on the server instead.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@fratzinger fratzinger changed the title feat(rateLimit): dryRun and onLimited feat(rateLimit): dryRun, onLimited, and no rateLimitRes on the error Nov 6, 2026
@fratzinger
fratzinger merged commit 82253c5 into main Nov 6, 2026
9 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@fratzinger
fratzinger deleted the feat/rate-limit-dry-run branch November 6, 2026 14:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@fratzinger
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.