fix(guard): replace internal caches with moka#2481
Closed
MasterPtato wants to merge 1 commit into05-27-fix_guard_add_metricsfrom
Closed
fix(guard): replace internal caches with moka#2481MasterPtato wants to merge 1 commit into05-27-fix_guard_add_metricsfrom
MasterPtato wants to merge 1 commit into05-27-fix_guard_add_metricsfrom
Conversation
Contributor
Author
There was a problem hiding this comment.
PR Summary
This PR replaces the internal caching mechanism in the guard service with the Moka caching library, providing better cache management and automatic TTL expiration.
- Added
mokadependency with future support inpackages/edge/infra/guard/core/Cargo.toml - Implemented cache TTL constants: 10 minutes for route cache, 1 hour for proxy state cache in
proxy_service.rs - Replaced
SccHashMapwithmoka::future::Cachefor route caching, rate limiters, and in-flight counters - Added mutex protection around rate limiters and in-flight counters for thread safety
- Updated metrics to use Moka's
entry_count()for accurate cache size tracking
2 file(s) reviewed, 1 comment(s)
Edit PR Review Bot Settings | Greptile
Comment on lines
+496
to
+502
| // Try to acquire from the limiter | ||
| let result = { | ||
| let mut limiter = limiter_arc.lock().await; | ||
| limiter.try_acquire() | ||
| }; | ||
|
|
||
| Ok(result) | ||
| } | ||
| Ok(result) |
There was a problem hiding this comment.
logic: Potential deadlock risk if the limiter lock is held during await points. Consider using a timeout on the lock acquisition.
Suggested change
| // Try to acquire from the limiter | |
| let result = { | |
| let mut limiter = limiter_arc.lock().await; | |
| limiter.try_acquire() | |
| }; | |
| Ok(result) | |
| } | |
| Ok(result) | |
| // Try to acquire from the limiter with timeout | |
| let result = match tokio::time::timeout( | |
| Duration::from_secs(5), | |
| limiter_arc.lock() | |
| ).await { | |
| Ok(Ok(mut limiter)) => limiter.try_acquire(), | |
| Ok(Err(_)) => false, // Lock poisoned | |
| Err(_) => false, // Lock timeout | |
| }; | |
| Ok(result) |
Deploying rivet with
|
| Latest commit: |
6caa5bf
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://0d946734.rivet.pages.dev |
| Branch Preview URL: | https://05-28-fix-guard-replace-inte.rivet.pages.dev |
This was referenced May 28, 2025
Closed
fcd1624 to
d958baa
Compare
37074b9 to
4d3b056
Compare
Deploying rivet-hub with
|
| Latest commit: |
6caa5bf
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://85366007.rivet-hub-7jb.pages.dev |
| Branch Preview URL: | https://05-28-fix-guard-replace-inte.rivet-hub-7jb.pages.dev |
Deploying rivet-studio with
|
| Latest commit: |
6caa5bf
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://3ab60aec.rivet-studio.pages.dev |
| Branch Preview URL: | https://05-28-fix-guard-replace-inte.rivet-studio.pages.dev |
d958baa to
4134605
Compare
4134605 to
d958baa
Compare
d958baa to
4134605
Compare
4134605 to
d958baa
Compare
d958baa to
4134605
Compare
4d3b056 to
bd93030
Compare
4134605 to
6caa5bf
Compare
bd93030 to
617a367
Compare
6caa5bf to
1fdb48c
Compare
This was referenced Jun 2, 2025
This was referenced Jun 3, 2025
Closed
This was referenced Jun 9, 2025
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.

Changes