Skip to content

Commit

Permalink
Merge bitcoin#13201: [qa] Handle disconnect_node race
Browse files Browse the repository at this point in the history
09c6699 [qa] Handle disconnect_node race (Suhas Daftuar)

Pull request description:

  Several tests call disconnect_nodes() on each node-pair in rapid
  succession, resulting in a race condition if a node disconnects a peer
  in-between the calculation of the nodeid's to disconnect and the
  invocation of the disconnectnode rpc call.  Handle this.

Tree-SHA512: 3078cea0006fcb507c812004a777c505eb1e9dda7c6df12dbbe72395a73ff6f6760f597b6492054f5487b34534417ddef5fbad30553c135c288c4b7cfce79223
  • Loading branch information
MarcoFalke authored and PastaPastaPasta committed Apr 3, 2020
1 parent 232bd29 commit 9d26907
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion test/functional/test_framework/util.py
Expand Up @@ -362,7 +362,14 @@ def set_node_times(nodes, t):

def disconnect_nodes(from_connection, node_num):
for peer_id in [peer['id'] for peer in from_connection.getpeerinfo() if "testnode%d" % node_num in peer['subver']]:
from_connection.disconnectnode(nodeid=peer_id)
try:
from_connection.disconnectnode(nodeid=peer_id)
except JSONRPCException as e:
# If this node is disconnected between calculating the peer id
# and issuing the disconnect, don't worry about it.
# This avoids a race condition if we're mass-disconnecting peers.
if e.error['code'] != -29: # RPC_CLIENT_NODE_NOT_CONNECTED
raise

# wait to disconnect
wait_until(lambda: [peer['id'] for peer in from_connection.getpeerinfo() if "testnode%d" % node_num in peer['subver']] == [], timeout=5)
Expand Down

0 comments on commit 9d26907

Please sign in to comment.