Skip to content

RateLimitingMiddleware implements IDisposable to avoid leaking timers#66435

Open
kvantetore wants to merge 1 commit intodotnet:mainfrom
kvantetore:fix/disposable-ratelimitingmiddleware
Open

RateLimitingMiddleware implements IDisposable to avoid leaking timers#66435
kvantetore wants to merge 1 commit intodotnet:mainfrom
kvantetore:fix/disposable-ratelimitingmiddleware

Conversation

@kvantetore
Copy link
Copy Markdown

@kvantetore kvantetore commented Apr 23, 2026

RateLimitingMiddleware implements IDisposable to avoid leaking timers

Change RateLimitingMiddleware from convention-based to DI activated and implement IDisposable in order to not leak memory

Description

Most of the implementation is pretty straight forward. The only thing that feels a bit off is the handling of options passed to UseRateLimiter(..., RateLimiterOptions options) (as opposed to the more idiomatic version passing options during DI registration). I moved some of the initialization code to an internal Initialize(...) and call the initialize method both from the constructor and from UseRateLimiter(..., RateLimiterOptions options)

Fixes #66434

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-middleware Includes: URL rewrite, redirect, response cache/compression, session, and other general middlewares community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RateLimitingMiddleware never disposes PartitionedRateLimiter causing memory leak

1 participant