fix(commands): add sliding-window rate limiting to system-modifying commands#51
Open
anshul23102 wants to merge 1 commit into
Open
fix(commands): add sliding-window rate limiting to system-modifying commands#51anshul23102 wants to merge 1 commit into
anshul23102 wants to merge 1 commit into
Conversation
1 task
Owner
|
Hi @anshul23102 , please resolve the conflicts. |
…ommands kill_process, apply_optimization, rollback_optimization, and apply_boot_optimization could be called as fast as a caller could issue them. A scripted flood of these commands could kill processes in a tight loop or repeatedly trigger optimizations, driving the system into an unstable state. Added a RateLimiter that tracks call timestamps per command in a trailing window using a monotonic clock, so it is unaffected by wall-clock adjustments. kill_process is capped at one call per second; the optimization commands are capped at five calls per minute. A rejected call does not record a timestamp, so it cannot extend the window. Each command checks the limiter before acquiring any other lock or modifying state. Added unit tests covering the per-command limit, independent tracking across commands, window expiry, and that rejected calls do not consume a slot. Closes Kanwaljeet1#48
e052567 to
661342a
Compare
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
kill_process,apply_optimization,rollback_optimization, andapply_boot_optimizationcould be called as fast as a caller could issue them. A scripted flood could kill processes in a tight loop or repeatedly trigger optimizations, driving the system into an unstable state.Related Issue
Closes #48
Root Cause
No throttling mechanism existed for any Tauri command. Every request was processed immediately.
Changes Made
src-tauri/src/system/rate_limiter.rsRateLimitertype. Tracks call timestamps per command in a trailing window usingInstant(monotonic, so unaffected by clock changes). Rejected calls do not record a timestamp.src-tauri/src/system/mod.rssrc-tauri/src/lib.rsrate_limitertoAppStateand anenforce_rate_limithelper.kill_processis capped at one call per second; the optimization commands at five per minute. Each command checks the limiter before acquiring any other lock.Testing Done
Checklist
cargo build