Skip to content

Commit c57e118

Browse files
sanityclaude
andcommitted
fix: fill subscriber address before calling .peer() to avoid panic
PR #2172 added detailed tracing that calls subscriber.peer() BEFORE filling in the address from source_addr. This causes a panic when the subscriber has PeerAddr::Unknown (NAT peers). The correct order (from PR #2171) is: 1. Check if address is unknown 2. Fill in address from source_addr 3. THEN call .peer() for tracing This regression was introduced when merging PR #2172's tracing improvements without preserving the correct order of operations. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent f9a1f7a commit c57e118

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

crates/core/src/operations/subscribe.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -410,25 +410,28 @@ impl Operation for SubscribeOp {
410410
// Fill in subscriber's external address from transport layer if unknown.
411411
// This is the key step where the first recipient (gateway) determines the
412412
// subscriber's external address from the actual packet source address.
413+
// IMPORTANT: Must fill address BEFORE any .peer() calls to avoid panic.
413414
let mut subscriber = subscriber.clone();
414415

416+
if subscriber.peer_addr.is_unknown() {
417+
if let Some(addr) = source_addr {
418+
subscriber.set_addr(addr);
419+
tracing::debug!(
420+
tx = %id,
421+
%key,
422+
subscriber_addr = %addr,
423+
"subscribe: filled subscriber address from source_addr"
424+
);
425+
}
426+
}
427+
415428
tracing::debug!(
416429
tx = %id,
417430
%key,
418-
subscriber_orig = %subscriber.peer(),
431+
subscriber = %subscriber.peer(),
419432
source_addr = ?source_addr,
420433
"subscribe: processing RequestSub"
421434
);
422-
423-
if let Some(addr) = source_addr {
424-
subscriber.set_addr(addr);
425-
tracing::debug!(
426-
tx = %id,
427-
%key,
428-
subscriber_updated = %subscriber.peer(),
429-
"subscribe: updated subscriber address from transport source"
430-
);
431-
}
432435
let own_loc = op_manager.ring.connection_manager.own_location();
433436

434437
if !matches!(

0 commit comments

Comments
 (0)