Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(comms): minor edge-case fix to handle inbound connection while dialing #3785

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions comms/src/connection_manager/dialer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ pub(crate) enum DialerRequest {
Option<oneshot::Sender<Result<PeerConnection, ConnectionManagerError>>>,
),
CancelPendingDial(NodeId),
NotifyNewInboundConnection(PeerConnection),
}

pub struct Dialer<TTransport, TBackoff> {
Expand Down Expand Up @@ -168,13 +169,29 @@ where
self.handle_dial_peer_request(pending_dials, peer, reply_tx);
},
CancelPendingDial(peer_id) => {
if let Some(mut s) = self.cancel_signals.remove(&peer_id) {
let _ = s.trigger();
self.cancel_dial(&peer_id);
},

NotifyNewInboundConnection(conn) => {
if conn.is_connected() {
self.resolve_pending_dials(conn);
}
},
}
}

fn cancel_dial(&mut self, peer_id: &NodeId) {
if let Some(mut s) = self.cancel_signals.remove(peer_id) {
let _ = s.trigger();
}
}

fn resolve_pending_dials(&mut self, conn: PeerConnection) {
let peer = conn.peer_node_id().clone();
self.reply_to_pending_requests(&peer, Ok(conn));
self.cancel_dial(&peer);
}

fn is_pending_dial(&self, node_id: &NodeId) -> bool {
self.cancel_signals.contains_key(node_id)
}
Expand Down Expand Up @@ -223,12 +240,8 @@ where
);
}

if self.pending_dial_requests.contains_key(&node_id) {
self.reply_to_pending_requests(&node_id, dial_result);
}

// Drop cancel signal
let _ = self.cancel_signals.remove(&node_id);
self.reply_to_pending_requests(&node_id, dial_result);
self.cancel_dial(&node_id);
}

pub async fn notify_connection_manager(&mut self, event: ConnectionManagerEvent) {
Expand Down
7 changes: 7 additions & 0 deletions comms/src/connection_manager/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,13 @@ where
},

PeerConnected(conn) => {
if conn.direction().is_inbound() {
// Notify the dialer that we have an inbound connection, so that is can resolve any pending dials.
let _ = self
.dialer_tx
.send(DialerRequest::NotifyNewInboundConnection(conn.clone()))
.await;
}
metrics::successful_connections(conn.peer_node_id(), conn.direction()).inc();
self.publish_event(PeerConnected(conn));
},
Expand Down