fix(gateway): fix cache key calculation#4077
fix(gateway): fix cache key calculation#4077MasterPtato wants to merge 1 commit into01-28-fix_remove_graceful_requirement_for_metrics_aggregatorfrom
Conversation
|
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.
How to use the Graphite Merge QueueAdd 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. |
c6e49a4 to
40593e6
Compare
340ee20 to
143c296
Compare
PR Review: fix(gateway): fix cache key calculationSummaryThis PR refactors the cache key calculation logic to properly handle WebSocket connections by moving the WebSocket detection earlier in the request lifecycle. This ensures consistent cache key generation across both routing and caching paths. Positive Changes1. Improved Architecture & Code Organization
2. Bug Fix: WebSocket Detection Timing
3. Enhanced Testability
Code Quality Observations1. Duplicate Code Pattern The target extraction logic is duplicated between cache/mod.rs:36-55 and routing/mod.rs:75-94. Both blocks parse Sec-WebSocket-Protocol and X-Rivet-Target identically. Consider extracting to a shared helper function. 2. Silent Error Handling In cache/mod.rs:27-31 and cache/mod.rs:59-61, errors from cache key generation are silently ignored. Add debug logging when cache key generation fails to help diagnose issues. 3. Inconsistent Path Hashing
This creates different cache keys for the same actor accessed via different routing methods. Example:
4. TODO Comments Both cache functions have identical TODO comments. Consider documenting the decision and removing them. Security ConsiderationsAll Good - URL encoding handled consistently, no injection risks, proper header validation. Performance Considerations1. Redundant Protocol Parsing 2. Hash Function Choice Test CoverageMissing test scenarios:
Recommendations SummaryHigh Priority:
Medium Priority: VerdictRecommendation: Approve with minor improvements The core bug fix is sound and improves the architecture. The identified issues are polish items that do not block merging, though addressing the cache key consistency question would prevent potential future bugs. Great work on identifying and fixing the WebSocket detection timing issue! |
PR Review: fix(gateway): fix cache key calculationSummaryThis PR fixes cache key calculation in the gateway by ensuring WebSocket detection happens before RequestContext is created, and refactors the cache key logic to handle both path-based and header/protocol-based routing consistently. Positive Changes
Issues and Concerns1. Silent Error Swallowing in Cache Key Function (cache/mod.rs:27-31, 59-61) Cache key generation errors are silently ignored and fall through to the next routing method. This masks legitimate errors (invalid actor IDs, malformed headers) that should fail fast. This creates debugging difficulty when cache keys are incorrectly generated and potential cache misses for valid requests. Recommendation: Add structured logging at minimum, or consider making errors explicit for certain failure modes (e.g., invalid actor ID format should probably fail the request rather than fall back). 2. Inconsistent TODO Comments (cache/pegboard_gateway.rs:29, 94) The TODOs ask if query should be excluded, while path-based routing uses stripped_path which includes the query string (routing/mod.rs:229-232). Cache key behavior for requests differing only in query params is unclear and potentially inconsistent. Recommendation: Decide whether query params should affect cache keys and update the code to match, then remove or clarify the TODOs. 3. Unnecessary String Allocation (cache/pegboard_gateway.rs:71, 85) Both branches convert to String only to immediately parse as Id (line 88). The intermediate string allocation is unnecessary and could be optimized. 4. Duplicate Protocol Parsing Logic The WebSocket protocol parsing for actor ID extraction is duplicated between cache key generation (cache/pegboard_gateway.rs:46-67) and routing logic (routing/pegboard_gateway.rs:84-116). Consider extracting to a shared helper function to reduce code duplication and ensure consistency. Minor Observations
Testing RecommendationsConsider adding tests for:
Priority RecommendationsMust Fix: Issue 1 (silent error swallowing) - add logging at minimum Should Fix: Issues 2 and 4 (query string TODO and duplicate parsing) Nice to Have: Issue 3 (string allocation optimization) Final AssessmentThe PR successfully fixes the WebSocket detection timing issue and improves code organization. The core logic is sound, but error handling could be more explicit and some code duplication should be addressed. The changes are functional and safe to merge with the suggested improvements applied either now or in a follow-up PR. |
40593e6 to
963ce72
Compare
143c296 to
66df968
Compare
Merge activity
|

No description provided.