Skip to content

web: reload the rate limiter when its configuration changes - #442

Open
mrueg wants to merge 1 commit into
prometheus:masterfrom
mrueg:fix/rate-limit-hot-reload
Open

web: reload the rate limiter when its configuration changes#442
mrueg wants to merge 1 commit into
prometheus:masterfrom
mrueg:fix/rate-limit-hot-reload

Conversation

@mrueg

@mrueg mrueg commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

The documentation says the configuration file "is read upon every http request", and users, headers and certificates behave that way. The rate limiter does not: it is built once when the server starts and captured in the handler, so editing rate_limit has no effect until a restart, with nothing in the logs to say so. Removing the section entirely does not lift the limit either.

Reproduced against master: started with burst: 1, interval: 1h, rewrote the file to remove rate_limit, and the next requests still returned 200 then 429.

Change

Build the limiter from the configuration the handler has just read, keeping the existing one while the values are unchanged. Rebuilding on every request would hand out a fresh burst each time and defeat the limit entirely, so the limiter is replaced only when interval or burst actually change, and the change is logged.

Replacing the limiter resets its token bucket, so a change to rate_limit starts the interval afresh — now stated in the docs. The limiter is still built once at startup so that an enabled rate limiter is reported in the logs there as before.

Tests

An end-to-end test that limits, lifts the limit by rewriting the file, and re-applies it; it fails against master at the first step after the rewrite. Plus a unit test that an unchanged configuration keeps the same limiter instance.

🤖 Generated with Claude Code

The documentation says the configuration file "is read upon every http
request", and users, headers and certificates behave that way. The rate
limiter did not: it was built once when the server started and captured in
the handler, so editing rate_limit had no effect until a restart, with
nothing in the logs to say so. Removing the section entirely did not lift
the limit either.

Build the limiter from the configuration the handler has just read, keeping
the existing one while the values are unchanged. Rebuilding on every
request would hand out a fresh burst each time and defeat the limit
entirely, so the limiter is replaced only when interval or burst actually
change, and the change is logged.

Replacing the limiter resets its token bucket, so a change to rate_limit
starts the interval afresh. That is now stated in the documentation.

The limiter is still built once at startup so that an enabled rate limiter
is reported in the logs there as it was before.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Manuel Rüger <manuel@rueg.eu>
@mrueg
mrueg force-pushed the fix/rate-limit-hot-reload branch from 11599d9 to 633968b Compare September 2, 2026 13:44
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