Skip to content

Commit 56954eb

Browse files
sanityclaude
andauthored
fix: register subscribers for locally-cached contracts (issue #2001) (#2004)
Co-authored-by: Claude <noreply@anthropic.com>
1 parent 3598a9b commit 56954eb

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

crates/core/src/operations/subscribe.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,22 @@ pub(crate) async fn request_subscribe(
8484
tracing::debug!(%key, "No remote peers available for subscription, checking locally");
8585

8686
if super::has_contract(op_manager, *key).await? {
87-
// We have the contract locally - complete operation immediately
88-
// Following Nacho's suggestion: use notify_node_event to tap into
89-
// result router directly without state transitions
90-
tracing::info!(%key, tx = %id, "Contract available locally, completing subscription via result router");
87+
// We have the contract locally - register subscription and complete immediately
88+
tracing::info!(%key, tx = %id, "Contract available locally, registering local subscription");
89+
90+
// CRITICAL FIX for issue #2001: Register subscriber in DashMap before completing
91+
// Without this, UPDATE operations won't find subscribers for locally-cached contracts
92+
let subscriber = op_manager.ring.connection_manager.own_location();
93+
if op_manager
94+
.ring
95+
.add_subscriber(key, subscriber.clone())
96+
.is_err()
97+
{
98+
tracing::error!(%key, tx = %id, "Failed to add local subscriber - max subscribers reached");
99+
// Continue anyway - client requested subscription and contract is local
100+
} else {
101+
tracing::debug!(%key, tx = %id, subscriber = %subscriber.peer, "Successfully registered local subscriber");
102+
}
91103

92104
// Use notify_node_event to deliver SubscribeResponse directly to client
93105
// This avoids the problem with notify_op_change overwriting the operation

crates/core/tests/operations.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,6 +1148,8 @@ async fn test_multiple_clients_subscription() -> TestResult {
11481148
}
11491149
}
11501150

1151+
tracing::info!("All clients subscribed, proceeding with UPDATE operation");
1152+
11511153
// Create a new to-do list by deserializing the current state, adding a task, and serializing it back
11521154
let mut todo_list: test_utils::TodoList = serde_json::from_slice(wrapped_state.as_ref())
11531155
.unwrap_or_else(|_| test_utils::TodoList {

0 commit comments

Comments
 (0)