mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-05-11 22:43:06 +02:00
6ac49373aatest: Add clean shutdown to Socks5Server (optout) Pull request description: Add clean shutdown to `Socks5Server` test utility, fix a sporadic CI failure. Closes #34849. The `Socks5Server` utility handles multiple incoming connections, which are handled in separate background threads. Its `stop()` method unblocks and waits for the main background thread cleanly, but it doesn't attempt to wait for the completion of handler threads. There is no guarantee that the handler threads are finished after `stop()` returns, which can lead to IO errors. In the reported sporadic test failures, the test in `p2p_private_broadcast.py` uses the Socks5 server, and makes a node connect to/through it. Then it stops the Socks5 server, and then it stops the node. However, if a connection handler is still active, that can lead to errors, as the socket is closed. The change attempts to fix this by storing all handler threads and connections, and attempting to shut them down before `stop()` returns. Notes: - ~~I was not able to reliably reproduce the failure locally.~~ Update: I could reproduce the failure, see https://github.com/bitcoin/bitcoin/issues/34849#issuecomment-4126331780 . Running the relevant test: ```sh build/test/functional/test_runner.py p2p_private_broadcast.py ``` ACKs for top commit: andrewtoth: re-ACK6ac49373aaachow101: ACK6ac49373aavasild: ACK6ac49373aaw0xlt: ACK6ac49373aaTree-SHA512: c63a62a516925252c450c9b7931539aedac2e44566bd4fe217aa54e6ca1438c8f50a100c714166b7cc67786b00f42c1a36e4916d63311842a77293cd2e102356