Skip to content

fix: prevent memory leak in rate limiter by cleaning up stale IPs#2

Open
Diode11-Alt wants to merge 1 commit intovision-dev1:mainfrom
Diode11-Alt:feature/fix-ratelimit-leak
Open

fix: prevent memory leak in rate limiter by cleaning up stale IPs#2
Diode11-Alt wants to merge 1 commit intovision-dev1:mainfrom
Diode11-Alt:feature/fix-ratelimit-leak

Conversation

@Diode11-Alt
Copy link
Copy Markdown

Fixes #1\n\nThe current rate_limit_storage dictionary in app.py stores IP addresses as keys but never removes them after their timestamps expire. This pull request adds a cleanup threshold to prevent an unbounded memory leak.

The in-memory rate_limit_storage dict never removes IP keys after
they expire. Over time on a busy server this leads to unbounded
memory growth. Added a garbage-collection pass that purges inactive
IPs once the storage exceeds 10k entries.
Copy link
Copy Markdown
Author

@Diode11-Alt Diode11-Alt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! This properly limits the storage mapping sizes and cleans up IPs with no more active timestamps. Excellent memory optimization fix.

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.

Memory leak in rate limiter storage

1 participant