Skip to content

Conversation

MasterPtato
Copy link
Contributor

Changes

@MasterPtato MasterPtato requested a review from NathanFlurry May 28, 2025 01:34
Copy link
Contributor Author

MasterPtato commented May 28, 2025

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more


How to use the Graphite Merge Queue

Add the label merge-queue to this PR to add it to the merge queue.

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

Copy link

@greptile-apps greptile-apps bot left a 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 in packages/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 with moka::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

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)
Copy link

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.

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)

Copy link

cloudflare-workers-and-pages bot commented May 28, 2025

Deploying rivet with  Cloudflare Pages  Cloudflare Pages

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

View logs

Copy link

cloudflare-workers-and-pages bot commented May 31, 2025

Deploying rivet-hub with  Cloudflare Pages  Cloudflare Pages

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

View logs

Copy link

cloudflare-workers-and-pages bot commented May 31, 2025

Deploying rivet-studio with  Cloudflare Pages  Cloudflare Pages

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

View logs

@MasterPtato MasterPtato force-pushed the 05-28-fix_guard_replace_internal_caches_with_moka branch from d958baa to 4134605 Compare May 31, 2025 00:54
@NathanFlurry NathanFlurry force-pushed the 05-28-fix_guard_replace_internal_caches_with_moka branch from 4134605 to d958baa Compare May 31, 2025 01:01
@MasterPtato MasterPtato force-pushed the 05-28-fix_guard_replace_internal_caches_with_moka branch from d958baa to 4134605 Compare May 31, 2025 01:04
@NathanFlurry NathanFlurry force-pushed the 05-28-fix_guard_replace_internal_caches_with_moka branch from 4134605 to d958baa Compare May 31, 2025 01:52
@MasterPtato MasterPtato force-pushed the 05-28-fix_guard_replace_internal_caches_with_moka branch from d958baa to 4134605 Compare May 31, 2025 02:05
@graphite-app graphite-app bot closed this Jun 3, 2025
@graphite-app graphite-app bot deleted the 05-28-fix_guard_replace_internal_caches_with_moka branch June 3, 2025 07:03
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.

1 participant