Skip to content

Conversation

vlad9486
Copy link
Contributor

Delay removal of the connection from the network state machine until the disconnection actually occurs at the TCP level.

@vlad9486 vlad9486 force-pushed the fix/disconnection branch 2 times, most recently from 3757dc8 to 5bbff1b Compare September 19, 2024 12:04
@vlad9486 vlad9486 marked this pull request as draft September 19, 2024 12:27
}
}
MioEvent::ConnectionDidCloseOnDemand(addr) => {
SubStore::dispatch(store, P2pNetworkSchedulerAction::Prune { addr })
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe u should dispatch P2pDisconnectionAction::Finish as well?

Copy link
Contributor

Choose a reason for hiding this comment

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

In fact I'd put SubStore::dispatch(store, P2pNetworkSchedulerAction::Prune { addr }) action in effects of the P2pDisconnectionAction::Finish

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is too big change and require more debugging to make it work properly. Let's allow connection where conn_state.closed is Some(..) to exist after Finish done.

@vlad9486 vlad9486 force-pushed the fix/disconnection branch 14 times, most recently from 0b134e2 to bff3ab4 Compare September 27, 2024 11:57
@vlad9486 vlad9486 force-pushed the fix/disconnection branch 5 times, most recently from cbd713f to cee0306 Compare September 30, 2024 08:06
@vlad9486 vlad9486 marked this pull request as ready for review September 30, 2024 09:47
@vlad9486 vlad9486 requested a review from binier September 30, 2024 09:49
// enabling condition
// it could be the case that the connection initialized again, so should not remove the state
let exist = store.state().p2p.ready().unwrap().peers.iter().any(|(_, x)| match &x.dial_opts {
Some(p2p::connection::outgoing::P2pConnectionOutgoingInitOpts::LibP2P(o)) => o.matches_socket_addr(addr.sock_addr),
Copy link
Contributor

Choose a reason for hiding this comment

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

For outgoing connections, socket address could match but it could be a new connection and this could be a stale action.

Copy link
Contributor

Choose a reason for hiding this comment

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

To properly fix this, it might require bigger changes, so maybe this is fine for now.

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, I just notice the unwrap, I remove it now.

Some(p2p::connection::outgoing::P2pConnectionOutgoingInitOpts::LibP2P(o)) => o.matches_socket_addr(addr.sock_addr),
_ => false,
});
if !exist {
Copy link
Contributor

Choose a reason for hiding this comment

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

This block will be executed if it's a webrtc connection, or if libp2p peer doesn't have the same socket addr. Is that the intended behavior? Maybe it was supposed to be just if exist {?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I should rename exist -> ready. When we removing connection, the peer should be in Disconnecting state, not Ready(..). In webrtc case MioEvent will not happen, so it is irrelevant.

To properly handle the case when new connection is initializing during old connection is still Disconnecting, maybe we need a counter in the state or in the key, in this map:

    pub peers: BTreeMap<PeerId, P2pPeerState>,

but anyway, disconnection is a millisecond at worst, and reconnection timeout is much bigger, so it should not be possible.

addr,
reason: reason.clone(),
});
dispatcher.push(P2pDisconnectionAction::Finish { peer_id: *peer_id });
Copy link
Contributor

Choose a reason for hiding this comment

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

If it gets insta finished, without any event from mio, then disconnecting state seems useless.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let's keep it for further improvement. I will make Finish an effect of Prune, but not now.

@vlad9486 vlad9486 merged commit 520fa80 into develop Oct 1, 2024
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants