From fab27726478d686dcd66d26d3b7b34aa323b8066 Mon Sep 17 00:00:00 2001 From: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz> Date: Tue, 27 Jan 2026 22:50:43 +0100 Subject: [PATCH] test: Fix all races after a socket is closed gracefully This waits for any disconnect (e.g. from a restart of one of the nodes) to fully happen before the next connect. Can be reviewed with the git option: --color-moved=dimmed-zebra --- .../test_framework/test_framework.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/test/functional/test_framework/test_framework.py b/test/functional/test_framework/test_framework.py index b809e68f4df..229ff893389 100755 --- a/test/functional/test_framework/test_framework.py +++ b/test/functional/test_framework/test_framework.py @@ -559,6 +559,17 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass): """ from_connection = self.nodes[a] to_connection = self.nodes[b] + + # Use subversion as peer id. Test nodes have their node number appended to the user agent string + from_connection_subver = from_connection.getnetworkinfo()['subversion'] + to_connection_subver = to_connection.getnetworkinfo()['subversion'] + + def find_conn(node, peer_subversion, inbound): + return next(filter(lambda peer: peer['subver'] == peer_subversion and peer['inbound'] == inbound, node.getpeerinfo()), None) + + self.wait_until(lambda: not find_conn(from_connection, to_connection_subver, inbound=False)) + self.wait_until(lambda: not find_conn(to_connection, from_connection_subver, inbound=True)) + ip_port = "127.0.0.1:" + str(p2p_port(b)) if peer_advertises_v2 is None: @@ -574,13 +585,6 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass): if not wait_for_connect: return - # Use subversion as peer id. Test nodes have their node number appended to the user agent string - from_connection_subver = from_connection.getnetworkinfo()['subversion'] - to_connection_subver = to_connection.getnetworkinfo()['subversion'] - - def find_conn(node, peer_subversion, inbound): - return next(filter(lambda peer: peer['subver'] == peer_subversion and peer['inbound'] == inbound, node.getpeerinfo()), None) - self.wait_until(lambda: find_conn(from_connection, to_connection_subver, inbound=False) is not None) self.wait_until(lambda: find_conn(to_connection, from_connection_subver, inbound=True) is not None)