Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge 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 e388f05b03..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
- Loading branch information