Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Fix old connections not being reused #1934

Merged
merged 2 commits into from
Mar 7, 2019

Conversation

tomaka
Copy link
Contributor

@tomaka tomaka commented Mar 6, 2019

When an issue happened on a connection, we would disable it.
However the connect_to_nodes method doesn't take into account existing but disabled connections. The connection would keep existing but be totally useless.

This PR fixes this.

#1777 is still there, but happens way less often.

@tomaka tomaka added the A0-please_review Pull request needs code review. label Mar 6, 2019
@tomaka tomaka force-pushed the fix-not-tried-again branch from 41ac2d3 to 6f4bcb4 Compare March 6, 2019 16:47
trace!(target: "sub-libp2p", "Connect-to-nodes round; attempting to fill {:?} slots",
num_to_open);

// We first try to enable existing connections.
for peer_id in &self.connected_peers {
if num_to_open == 0 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this if be outside at the outside of this for loop?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, that's because I forgot to add num_to_open -= 1; inside the loop.

}

if let Some((_, expire)) = self.banned_peers.iter().find(|(p, _)| p == peer_id) {
if *expire >= Instant::now() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe take Instance::now() once?

continue;
}

if let Some((_, expire)) = self.banned_peers.iter().find(|(p, _)| p == peer_id) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just out of curiosity, do we hold connection to a peer that is banned?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Banned peers can still perform Kademlia queries.
The connection should however close after a few seconds because it is marked as "useless".

}

trace!(target: "sub-libp2p", "Enabling custom protocols with {:?} (active)", peer_id);
self.events.push(NetworkBehaviourAction::SendEvent {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we enabled this "old" connection, do we still need to try to open a new connection?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That doesn't open a new connection. It sends a message to the handler of the existing connection that it should enable it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I really wanted to ask, shouldn't we return after sending this event?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We continue looping until num_to_open is 0.

@bkchr bkchr merged commit c4ca27f into paritytech:master Mar 7, 2019
@tomaka tomaka deleted the fix-not-tried-again branch March 7, 2019 22:01
MTDK1 pushed a commit to bdevux/substrate that referenced this pull request Apr 12, 2019
* Fix old connections not being reused

* Address issues
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-please_review Pull request needs code review.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants