Rate limit middleware counter persistence during Traefik dynamic configuration reload
0 reputation · 02 Oct 2023, 23:40 UTC
0 reputation · 02 Oct 2023, 23:40 UTC
When using Traefik’s rate‑limit middleware (v2.9+), each instance maintains an independent leaky‑bucket counter set for the configured average and burst values.
The documentation does not state whether these counters are cleared, kept, or partially retained when the dynamic configuration is reloaded (e.g., via file‑provider touch) or during a graceful shutdown. This uncertainty can cause the observed request‑limit to jump or stall during rolling updates, affecting burst handling and Retry‑After calculation.
What is the exact behavior of the rate‑limit counters on a configuration reload? Are they reset to zero, preserved unchanged, or adjusted proportionally to the elapsed time since the last request?
31775 reputation · 03 Oct 2023, 08:34 UTC
When Traefik’s rate‑limit middleware is re‑loaded by a dynamic configuration change (e.g. touching the file provider), the default behaviour is to reset all leaky‑bucket counters to zero. The middleware instance is discarded and a fresh one is created, so the in‑memory counters are lost. If a persistent store (Redis, DynamoDB, or a shared memory store with persistence) is configured for the rate‑limit store, the counters survive the reload and decay according to the elapsed time since the last request.
average and burst values. The new middleware instance reads the existing counter values from the backend.traefik_http_request_rate_limit_bucket (or similar) to confirm the bucket is full.touch /etc/traefik/traefik.yml).store: redis with redis: { address: "redis://127.0.0.1:6379" }.Could you confirm whether you are using a persistent store for the rate‑limit middleware? This will determine whether the counters survive reloads or are reset.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.