-
Notifications
You must be signed in to change notification settings - Fork 114
fix(guard): replace internal caches with moka #2481
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(guard): replace internal caches with moka #2481
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
moka
dependency 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
SccHashMap
withmoka::future::Cache
for 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
// 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: Potential deadlock risk if the limiter lock is held during await points. Consider using a timeout on the lock acquisition.
// 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 |
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
Changes