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

[DRAFT] Quit application: Stop P2P faster #10668

Conversation

kiminuo
Copy link
Collaborator

@kiminuo kiminuo commented May 11, 2023

Fixes #10155

There are 2 commits:

  1. 80b8a71 - I think we should have this connect cancellation in place.
  2. 0bf9653 corresponds with kiminuo/NBitcoin@46dfc4b commit (NBitcoin.Kimi fork 7.0.25.1)

Explanation

Now what is happening. We have P2pNetwork.cs where we initialize a NodesGroup:

var nodes = new NodesGroup(Network, connectionParameters, requirements: Constants.NodeRequirements);

so on NBitcoin's side we start NodesGroup.StartConnecting(). So far so good.

The process of stopping P2pNetwork relies on NodesGroup.Disconnect() and there is a slight issue in the NBitcoin impl:

/// <summary>
/// Drop connection to all connected nodes
/// </summary>
public void Disconnect()
{
	_Disconnect.Cancel();
	_ConnectedNodes.DisconnectAll();
}

... and the issue is that NBitcoin does not cancel connecting of a not-yet-connected node (if there is one) in NodesGroup.StartConnecting. How is that possible? One would expect that:

  1. _Disconnect.Cancel(); stops connecting to any not-yet-connected node, and
  2. that _ConnectedNodes.DisconnectAll(); disconnects all connected nodes.

The issue seems to be in

and the issue is that _Connection (NodeConnection) has its own cancellation token that is not being cancelled by NodesGroup.Disconnect() (here).

And that's why kiminuo/NBitcoin@46dfc4b makes sense to me.

@kiminuo kiminuo force-pushed the feature/2023-05-11-NBitcoin-fork-stopping-P2P-connections-fast branch from cbad46f to a7ee485 Compare May 11, 2023 10:37
@kiminuo kiminuo force-pushed the feature/2023-05-11-NBitcoin-fork-stopping-P2P-connections-fast branch from a7ee485 to 86ee134 Compare May 11, 2023 10:38
@kiminuo
Copy link
Collaborator Author

kiminuo commented Jun 19, 2023

#10325 (comment) -> closing

@kiminuo kiminuo closed this Jun 19, 2023
@molnard
Copy link
Collaborator

molnard commented Jun 19, 2023

If this fixes #10155 it should not be closed because of #10325.

I would keep this open. Do you think it is worth fixing this in NBitcoin?

@kiminuo kiminuo reopened this Jun 19, 2023
@kiminuo
Copy link
Collaborator Author

kiminuo commented Jun 19, 2023

I would keep this open. Do you think it is worth fixing this in NBitcoin?

Yeah, it would be good to fix it there1. If my assessment is correct, NBitcoin's users would benefit from it as well.

Footnotes

  1. Given how NBitcoin's P2P code is written, I think it would be for the best not to use it at all and have our own code instead.

@stale
Copy link

stale bot commented Sep 17, 2023

This has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Sep 17, 2023
@stale stale bot closed this Mar 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Hanging Wasabi process
2 participants