Skip to content

Commit 09c6699

Browse files
committed
[qa] Handle disconnect_node race
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.
1 parent 08c1caf commit 09c6699

File tree

1 file changed

+8
-1
lines changed
  • test/functional/test_framework

1 file changed

+8
-1
lines changed

test/functional/test_framework/util.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,14 @@ def set_node_times(nodes, t):
351351

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

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

0 commit comments

Comments
 (0)