Skip to content

Conversation

@maflcko
Copy link
Member

@maflcko maflcko commented Nov 8, 2017

Disconnecting the connection with index=0 makes no sense when there are more than one connections, as the list "rotates around" and populates index 0 after del.

Just disconnect all NodeConns in any case.

@fanquake fanquake added the Tests label Nov 8, 2017
p2p_conns = []

for i in range(3):
for _ in range(3):

Choose a reason for hiding this comment

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

Interested in the use of the underscore as the variable name here, did some reading and from what I've read use of the underscore only works as something other than a variable name when used in an interactive python shell? Other than that people seem to believe it's a bad naming convention.

Context: https://stackoverflow.com/questions/26895362/what-does-in-python-do

Copy link
Member

Choose a reason for hiding this comment

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

_ as a variable name in python is a convention to indicate that the result won't be used.

Choose a reason for hiding this comment

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

Thanks for the explanation, makes sense.

"""Close all p2p connections to the node."""
for _ in range(len(self.p2ps)):
index = 0
# Connection could have already been closed by other end.
Copy link
Member

Choose a reason for hiding this comment

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

Is the order of deletion relevant? If not, something like this is both easier to read and likely more efficient:

for x in self.p2ps:
    if x.connection is not None:
        x.connection.disconnect_node()
self.p2ps = []

Copy link
Member Author

Choose a reason for hiding this comment

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

No, the order is not relevant. Will switch to your suggestion. (I tried to minimize the --ignore-all-space diff)

@maflcko maflcko force-pushed the Mf1711-qaNodeConnDisconnectAll branch 2 times, most recently from fa3408a to fa3a437 Compare November 13, 2017 20:26
@maflcko maflcko force-pushed the Mf1711-qaNodeConnDisconnectAll branch from fa3a437 to faaa7db Compare November 13, 2017 20:27
@laanwj
Copy link
Member

laanwj commented Nov 14, 2017

utACK faaa7db

@laanwj laanwj merged commit faaa7db into bitcoin:master Nov 14, 2017
laanwj added a commit that referenced this pull request Nov 14, 2017
faaa7db qa: Only allow disconnecting all NodeConns (MarcoFalke)

Pull request description:

  Disconnecting the connection with `index=0` makes no sense when there are more than one connections, as the list "rotates around" and populates index 0 after `del`.

  Just disconnect all NodeConns in any case.

Tree-SHA512: e5cf540823fccb31634b5a11501f54222be89862e80ccafc28bc06726480f8d2153b8c1b6f859fa6a6d087876251d48a6c6035bccdaaf16831e300bc17ff613d
@maflcko maflcko deleted the Mf1711-qaNodeConnDisconnectAll branch November 14, 2017 16:08
codablock pushed a commit to codablock/dash that referenced this pull request Oct 3, 2019
faaa7db qa: Only allow disconnecting all NodeConns (MarcoFalke)

Pull request description:

  Disconnecting the connection with `index=0` makes no sense when there are more than one connections, as the list "rotates around" and populates index 0 after `del`.

  Just disconnect all NodeConns in any case.

Tree-SHA512: e5cf540823fccb31634b5a11501f54222be89862e80ccafc28bc06726480f8d2153b8c1b6f859fa6a6d087876251d48a6c6035bccdaaf16831e300bc17ff613d
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants