From bbb292c8e65ec68428fae285b02751ef2ffcc363 Mon Sep 17 00:00:00 2001 From: cloudhead Date: Tue, 25 Jun 2024 23:42:08 +0200 Subject: [PATCH] node: Don't panic on connection logic error It seems like the underlying network library has a bug, and transport handovers don't always happen. --- radicle-node/src/service.rs | 6 ++++++ radicle-node/src/service/session.rs | 2 +- radicle-node/src/wire/protocol.rs | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/radicle-node/src/service.rs b/radicle-node/src/service.rs index 1d8575a5..88dd9106 100644 --- a/radicle-node/src/service.rs +++ b/radicle-node/src/service.rs @@ -1335,6 +1335,12 @@ where // In this scenario, it's possible that our peer is persistent, and // disconnected. We get an inbound connection before we attempt a re-connection, // and therefore we treat it as a regular inbound connection. + // + // It's also possible that a disconnection hasn't gone through yet and our + // peer is still in connected state here, while a new inbound connection from + // that same peer is made. This results in a new connection from a peer that is + // already connected from the perspective of the service. This appears to be + // a bug in the underlying networking library. let peer = e.get_mut(); debug!( target: "service", diff --git a/radicle-node/src/service/session.rs b/radicle-node/src/service/session.rs index 8510d677..beeb6ea8 100644 --- a/radicle-node/src/service/session.rs +++ b/radicle-node/src/service/session.rs @@ -231,7 +231,7 @@ impl Session { self.last_active = since; if let State::Connected { .. } = &self.state { - panic!("Session::to_connected: session is already in 'connected' state"); + log::error!(target: "service", "Session {} is already in 'connected' state, resetting..", self.id); }; self.state = State::Connected { since, diff --git a/radicle-node/src/wire/protocol.rs b/radicle-node/src/wire/protocol.rs index aed6a4a5..b4f903f2 100644 --- a/radicle-node/src/wire/protocol.rs +++ b/radicle-node/src/wire/protocol.rs @@ -491,7 +491,7 @@ where &DisconnectReason::connection(), ); } else { - log::warn!(target: "wire", "Tried to cleanup unknown peer with id={id} (fd={fd})"); + log::debug!(target: "wire", "Tried to cleanup unknown peer with id={id} (fd={fd})"); } } }