Skip to content

Commit b3106be

Browse files
committed
Merge bitcoin/bitcoin#29898: test: Fix intermittent issue in p2p_handshake.py
6b02c11 test: Fix intermittent issue in p2p_handshake.py (stratospher) Pull request description: When establishing outbound connections [`TestNode` --------> `P2PConnection`], `P2PConnection` listens for a single connection from `TestNode` on a [port which is fixed based on `p2p_idx`](https://github.com/bitcoin/bitcoin/blob/312f54278fd972ba3557c6a5b805fd244a063959/test/functional/test_framework/p2p.py#L746). If we reuse the same port when disconnecting and establishing connections again, we might hit this scenario where: - disconnection is done on python side for `P2PConnection` - disconnection not complete on c++ side for `TestNode` - we're trying to establish a new connection on same port again Prevent this scenario from happening by ensuring disconnection on c++ side for TestNode as well. One way to reproduce this on master would be adding a sleep statement before disconnection happens on c++ side. ```diff diff --git a/src/net.cpp b/src/net.cpp index e388f05..62507d1f39 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -2112,6 +2112,7 @@ void CConnman::SocketHandlerConnected(const std::vector<CNode*>& nodes, if (!pnode->fDisconnect) { LogPrint(BCLog::NET, "socket closed for peer=%d\n", pnode->GetId()); } + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); pnode->CloseSocketDisconnect(); } else if (nBytes < 0) ``` ACKs for top commit: maflcko: lgtm ACK 6b02c11 mzumsande: Tested ACK 6b02c11 BrandonOdiwuor: Tested ACK 6b02c11 theStack: Tested ACK 6b02c11 glozow: ACK 6b02c11 Tree-SHA512: 69509edb61ba45739fd585b6cc8a254f412975c124a5b5a52688288ecaaffd264dd76019b8290cc34c26c3ac2dfe477965ee5a11d7aabdd8e4d2a75229a4a068
2 parents 04c90f1 + 6b02c11 commit b3106be

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

test/functional/p2p_handshake.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ def add_outbound_connection(self, node, connection_type, services, wait_for_disc
4141
peer.sync_with_ping()
4242
peer.peer_disconnect()
4343
peer.wait_for_disconnect()
44+
self.wait_until(lambda: len(node.getpeerinfo()) == 0)
4445

4546
def test_desirable_service_flags(self, node, service_flag_tests, desirable_service_flags, expect_disconnect):
4647
"""Check that connecting to a peer either fails or succeeds depending on its offered

0 commit comments

Comments
 (0)