Skip to content

Commit 5b9f141

Browse files
authored
Do not panic on stale messages from connections (#3764)
Fixes #3759
1 parent 3ce0ca7 commit 5b9f141

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

bootstore/src/schemes/v0/peer.rs

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -752,14 +752,17 @@ impl Node {
752752
let Some(accepted_handle) =
753753
self.accepted_connections.remove(&accepted_addr) else
754754
{
755-
error!(
755+
warn!(
756756
self.log,
757-
"Missing AcceptedConnHandle";
757+
concat!(
758+
"Missing AcceptedConnHandle: ",
759+
"Stale ConnectedAcceptor msg"
760+
);
758761
"accepted_addr" => accepted_addr.to_string(),
759762
"addr" => addr.to_string(),
760763
"remote_peer_id" => peer_id.to_string()
761764
);
762-
panic!("Missing AcceptedConnHandle");
765+
return;
763766
};
764767

765768
// Ignore the stale message if the unique_id doesn't match what
@@ -818,13 +821,13 @@ impl Node {
818821
self.established_connections
819822
.insert(peer_id.clone(), handle);
820823
} else {
821-
error!(
824+
warn!(
822825
self.log,
823-
"Missing PeerConnHandle";
826+
"Missing PeerConnHandle; Stale ConnectedInitiator msg";
824827
"addr" => addr.to_string(),
825828
"remote_peer_id" => peer_id.to_string()
826829
);
827-
panic!("Missing PeerConnHandle");
830+
return;
828831
}
829832

830833
if let Err(e) =
@@ -846,12 +849,12 @@ impl Node {
846849
return;
847850
}
848851
} else {
849-
error!(
852+
warn!(
850853
self.log,
851-
"Missing PeerConnHandle";
854+
"Missing PeerConnHandle: Stale Disconnected msg";
852855
"remote_peer_id" => peer_id.to_string()
853856
);
854-
panic!("Missing PeerConnHandle");
857+
return;
855858
}
856859
warn!(self.log, "peer disconnected {peer_id}");
857860
let handle =
@@ -932,6 +935,7 @@ impl Node {
932935
self.conn_tx.clone(),
933936
)
934937
.await;
938+
info!(self.log, "Initiating connection to new peer: {addr}");
935939
self.initiating_connections.insert(addr, handle);
936940
}
937941
}
@@ -952,6 +956,11 @@ impl Node {
952956
async fn remove_peer(&mut self, addr: SocketAddrV6) {
953957
if let Some(handle) = self.initiating_connections.remove(&addr) {
954958
// The connection has not yet completed its handshake
959+
info!(
960+
self.log,
961+
"Peer removed: deleting initiating connection";
962+
"remote_addr" => addr.to_string()
963+
);
955964
let _ = handle.tx.send(MainToConnMsg::Close).await;
956965
} else {
957966
// Do we have an established connection?
@@ -960,6 +969,12 @@ impl Node {
960969
.iter()
961970
.find(|(_, handle)| handle.addr == addr)
962971
{
972+
info!(
973+
self.log,
974+
"Peer removed: deleting established connection";
975+
"remote_addr" => addr.to_string(),
976+
"remote_peer_id" => id.to_string(),
977+
);
963978
let _ = handle.tx.send(MainToConnMsg::Close).await;
964979
// probably a better way to avoid borrowck issues
965980
let id = id.clone();

0 commit comments

Comments
 (0)