Skip to content

Commit 5fec28d

Browse files
sanityclaude
andcommitted
refactor: improve proximity cache logging per review feedback
Address PR review feedback: - Add explicit loop with debug logging for disconnected proximity neighbors (aligns with get_broadcast_targets_update pattern) - Log the count of proximity neighbors found for debugging - Add code comment documenting the async race condition with CacheAnnounce messages and why the fallback handles it 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 0062b13 commit 5fec28d

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

crates/core/src/operations/update.rs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -929,12 +929,38 @@ pub(crate) async fn request_update(
929929
// This is critical for peer-to-peer updates when peers are directly connected
930930
// but not explicitly subscribed (e.g., River chat rooms where both peers cache
931931
// the contract but haven't established a subscription tree).
932-
let target_from_proximity = op_manager
932+
//
933+
// Note: The proximity cache is populated asynchronously via CacheAnnounce messages,
934+
// so there may be a brief race window after a peer caches a contract before its
935+
// neighbors receive the announcement. This is acceptable - the ring-based fallback
936+
// handles this case, and the proximity cache improves the common case where
937+
// announcements have propagated.
938+
let proximity_neighbors: Vec<_> = op_manager
933939
.proximity_cache
934940
.neighbors_with_contract(&key)
935941
.into_iter()
936942
.filter(|addr| addr != &sender_addr)
937-
.find_map(|addr| op_manager.ring.connection_manager.get_peer_by_addr(addr));
943+
.collect();
944+
945+
let mut target_from_proximity = None;
946+
for addr in &proximity_neighbors {
947+
match op_manager.ring.connection_manager.get_peer_by_addr(*addr) {
948+
Some(peer) => {
949+
target_from_proximity = Some(peer);
950+
break;
951+
}
952+
None => {
953+
// Neighbor is in proximity cache but no longer connected.
954+
// This is normal during connection churn - the proximity cache
955+
// will be cleaned up when the disconnect is processed.
956+
tracing::debug!(
957+
%key,
958+
peer = %addr,
959+
"UPDATE: Proximity cache neighbor not connected, trying next"
960+
);
961+
}
962+
}
963+
}
938964

939965
let target = if let Some(remote_subscriber) = target_from_subscribers {
940966
remote_subscriber
@@ -944,6 +970,7 @@ pub(crate) async fn request_update(
944970
tracing::debug!(
945971
%key,
946972
target = ?proximity_neighbor.socket_addr(),
973+
proximity_neighbors_found = proximity_neighbors.len(),
947974
"UPDATE: Using proximity cache neighbor as target"
948975
);
949976
proximity_neighbor

0 commit comments

Comments
 (0)