Skip to content

Commit c0e45c4

Browse files
sanityclaude
andcommitted
fix: race condition in hop-by-hop routing where state saved after send
The operation state was being pushed AFTER sending the forwarded message. In cases where the remote peer responded quickly, the response could arrive before the state was saved, causing load_or_init to fail to find the operation (returning OpNotPresent). This caused flaky failures in test_put_contract_three_hop_returns_response in CI environments where timing was faster than local testing. Fix: Push state to op_manager BEFORE sending the message to ensure the state is always available when the response arrives. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 4621744 commit c0e45c4

File tree

1 file changed

+4
-1
lines changed
  • crates/core/src/operations

1 file changed

+4
-1
lines changed

crates/core/src/operations/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,11 @@ where
169169
tracing::debug!(%id, "operation in progress");
170170
if let Some(target) = next_hop {
171171
tracing::debug!(%id, ?target, "sending updated op state");
172-
network_bridge.send(target, msg).await?;
172+
// IMPORTANT: Push state BEFORE sending message to avoid race condition.
173+
// If we send first, a fast response might arrive before the state is saved,
174+
// causing load_or_init to fail to find the operation.
173175
op_manager.push(id, updated_state).await?;
176+
network_bridge.send(target, msg).await?;
174177
} else {
175178
tracing::debug!(%id, "queueing op state for local processing");
176179
debug_assert!(

0 commit comments

Comments
 (0)