-
Notifications
You must be signed in to change notification settings - Fork 129
fix(guard): include method in cache key #3338
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): include method in cache key #3338
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
3 Skipped Deployments
|
Pull Request Review: Include Method in Cache KeyOverviewThis PR fixes a caching issue by including the HTTP method in the cache key generation. This ensures that different HTTP methods (GET, POST, PUT, DELETE, etc.) to the same path produce distinct cache entries. Positive Aspects ✓
Issues & Recommendations1. Test Coverage Gap
|
3689716 to
dce28f8
Compare
0454643 to
d9f9f0c
Compare
PR Review: Include Method in Cache KeySummaryThis PR adds the HTTP method to the cache key calculation, which is an important fix to prevent incorrect cache hits between different HTTP methods (GET vs POST, etc.) on the same path. Code Quality and Correctness ✅Positive Changes:
Architecture:
Critical Issue Found 🔴Missing Test Update: Current test code (lines 477-492): pub fn create_test_cache_key_fn() -> CacheKeyFn {
Arc::new(
move |hostname: &str,
path: &str,
_port_type: rivet_guard_core::proxy_service::PortType,
_headers: &hyper::HeaderMap| {
// Missing method parameter!
let hostname_only = hostname.split(':').next().unwrap_or(hostname);
let mut hasher = DefaultHasher::new();
hostname_only.hash(&mut hasher);
path.hash(&mut hasher);
// Method is NOT being hashed here
Ok(hasher.finish())
},
)
}The signature is missing the
Required Fix: pub fn create_test_cache_key_fn() -> CacheKeyFn {
Arc::new(
move |hostname: &str,
path: &str,
method: &hyper::Method, // Add this parameter
_port_type: rivet_guard_core::proxy_service::PortType,
_headers: &hyper::HeaderMap| {
let hostname_only = hostname.split(':').next().unwrap_or(hostname);
let mut hasher = DefaultHasher::new();
hostname_only.hash(&mut hasher);
path.hash(&mut hasher);
method.as_str().hash(&mut hasher); // Add this line
Ok(hasher.finish())
},
)
}Test Coverage
|
PR Review: fix(guard): include method in cache keySummaryThis PR adds HTTP method to the cache key generation for the guard proxy service. This is an important bug fix that prevents incorrect cache hits when the same path is accessed with different HTTP methods (e.g., GET vs POST vs PUT). ✅ Code Quality & Best PracticesStrengths:
Style adherence:
🐛 Potential IssuesNone identified - The implementation is sound and addresses the bug correctly. ⚡ Performance ConsiderationsPositive:
Neutral:
🔒 Security ConcernsPositive:
🧪 Test CoverageConcern:
Recommendation:
Example test structure: #[tokio::test]
async fn test_cache_key_includes_method() {
// Setup proxy with mock routing function
// Send GET request to /test/path
// Verify response A
// Send POST request to /test/path
// Verify response B (different from A, not cached)
}📋 Overall AssessmentRating: ✅ Approve with minor recommendation This is a well-implemented bug fix that addresses a real issue in the caching logic. The change is:
Recommendation: Merge after considering adding test coverage for method-specific cache keys. 📝 Additional NotesThe refactoring is clean and maintains backward compatibility in terms of the overall architecture. The function signature change is internal to the guard packages and properly propagated throughout the codebase. |
d9f9f0c to
705c6ca
Compare
PR Review: fix(guard): include method in cache keySummaryThis PR fixes a critical bug where HTTP requests with different methods (GET, POST, PUT, DELETE, etc.) to the same endpoint were being cached together. The fix properly includes the HTTP method in the cache key calculation. Code Quality ✅Positive aspects:
Potential Issues 🔍Critical - Cache invalidation:
Recommendation: Consider whether a cache clear or version bump is needed during deployment. Code observation: // Capture headers and method before request is consumed
let req_headers = req.headers().clone();
let req_method = req.method().clone();The comment is helpful, but Test Coverage
|
705c6ca to
28148fb
Compare
30bd99b to
20dd048
Compare
|
Deployment failed with the following error: Learn More: https://vercel.com/docs/limits#rate-limits |
PR Review: fix(guard): include method in cache keyOverviewThis PR addresses a critical bug where HTTP requests with different methods (GET, POST, PUT, DELETE, etc.) to the same path were sharing cache entries. The fix correctly adds the HTTP method to the cache key calculation across all relevant code paths. ✅ Strengths
🐛 Critical Issue FoundTest Helper Function Missing Hash Implementation In Current code: let mut hasher = DefaultHasher::new();
hostname_only.hash(&mut hasher);
path.hash(&mut hasher);
// method is NOT being hashed here!
Ok(hasher.finish())This creates a discrepancy between production and test behavior:
Impact:
Required Fix: let mut hasher = DefaultHasher::new();
hostname_only.hash(&mut hasher);
path.hash(&mut hasher);
method.as_str().hash(&mut hasher); // Add this line
Ok(hasher.finish())Also update the parameter name from 📋 Test Coverage GapWhile the codebase has extensive integration tests (proxy, websocket, rate limiting, etc.), there are no specific tests that verify cache key differentiation by HTTP method. Recommendation: Consider adding a test that explicitly verifies:
🔒 Security ImpactPositive: This change prevents a security issue where:
⚡ Performance ImpactNeutral/Positive:
📝 Code Style✅ Follows CLAUDE.md conventions:
Overall AssessmentRating: This is an excellent bug fix with correct implementation in production code. However, the test helper function must be updated to match production behavior before merging. Action Items:
Once the test helper is fixed, this PR will be ready to merge. The core implementation is solid and addresses an important correctness issue in the caching layer. Files Reviewed:
|
Merge activity
|

No description provided.