fix: address cache consistency issues between L1 and L2#126
Conversation
- cache.go: return copy of byte slice from Get() to prevent mutation corruption (#106) - redis.go: Invalidate() now deletes key from Redis before publishing (#104) - redis.go: add RemainingTTL() method to get Redis TTL for L1 population (#115) - server.go: add sharded per-key locking to close TOCTOU race window (#107) - server.go: zone updates call Redis.Invalidate() to flush L2 and publish to all nodes (#105)
|
Warning Rate limit exceeded
To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (6)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Review rate limit: 0/1 reviews remaining, refill in 24 minutes and 30 seconds.Comment |
- cache.go: replace append([]byte(nil), ...) idiom with explicit make/copy - server.go: add tryLock spin loop before blocking on cache locks
- Lock was held during potentially slow L3 (DB) resolution, serializing all requests sharing the same lock shard - Restructure so lock is released before L3 resolution begins; use fromL2 flag to return early if L2 hit - Remove tryLock spin loop (blocked indefinitely under contention without runtime spinning) - Remove runtime import since spin loop was the only use
Summary
Fix 5 cache consistency issues between L1 (in-memory) and L2 (Redis) cache layers in the DNS server.
Changes
Get()now returns a copy of the cached data, not the internal reference — prevents mutation corruption whenhandlePacket()rewrites the DNS transaction IDInvalidate()now deletes the key from Redis before publishing the invalidation eventRemainingTTL()method to query Redis TTL for L1 populationRedis.Invalidate()to flush L2 and publish to all nodesTest plan
go build ./...passesgo test ./internal/dns/server/... -racepasses