Repository navigation
fix(cache): cancel-safe dedup of concurrent origin pull-through - #330
Conversation
There was a problem hiding this comment.
Code Review
This pull request implements request coalescing in the cache engine to prevent redundant origin fetches and introduces a rate_per_mb field to the gossip protocol. It also adds validation for OTLP endpoints and improves gossip version checking. Feedback highlights a race condition in the coalescing logic that could still allow duplicate fetches and a wire-compatibility issue caused by the structural changes to the gossip protocol's announcement body.
ca0824c to
d0f3778
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces request coalescing in the cache engine to prevent duplicate origin fetches and adds a rate_per_mb field to the NodeAnnounceBody struct. Feedback identifies a critical cancellation safety issue in the coalescing logic that could lead to task hangs if a future is dropped. Additionally, the modification of NodeAnnounceBody is flagged for breaking backward compatibility and violating architectural constraints regarding frozen wire formats.
…lescing Concurrent CacheEngine::get calls for the same uncached hash now coalesce into a single origin fetch via an inflight Notify map. The check-and-insert is a single lock acquisition, eliminating the race where multiple tasks could see an empty map and all proceed to pull. Cleanup is wrapped in a Drop guard (InflightGuard) so the entry is removed and waiters are woken even when the owning future is cancelled mid-pull — without this, a cancelled pull would orphan the entry and hang every subsequent request for the same hash forever. Closes #305 Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
2770763 to
4632210
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request implements request coalescing in the cache engine to prevent redundant origin fetches for the same hash. It introduces an inflight map tracked via tokio::sync::Notify and utilizes an RAII InflightGuard to ensure that map entries are cleared and waiting tasks are notified, even if the owning task is cancelled or panics. New tests verify that concurrent requests are correctly coalesced and that the internal state is properly cleaned up. I have no feedback to provide.
Summary
Concurrent
CacheEngine::getcalls for the same uncached hash now coalesce into a single origin fetch via an inflightNotifymap. The check-and-insert is a single lock acquisition, eliminating the race where multiple tasks could see an empty map and all proceed to pull.Cleanup is wrapped in a
Dropguard (InflightGuard) so the entry is removed and waiters are woken even when the owning future is cancelled mid-pull — without this, a cancelled pull would orphan the entry and hang every subsequent request for the same hash forever.Closes #305
Notes
rate_per_mbgossip change originally bundled here. Discussion concluded that an unsigned/spoofable rate hint isn't useful (peers can bait-and-switch with a higher rate in the signedProbeResponse), and the canonical rate is already in the probe response per ADR 005. protocol: NodeAnnounceBody.rate_per_mb field is absent, forcing clients to correlate ProbeResponse rate quotes with gossip peer entries using only node_id, with no cached rate available during peer selection before probing #310 will be revisited (or closed) separately.Test plan
🤖 Generated with Claude Code