On the master branch, when compiling without external signer support, the bench_bitcoin.exe
does not initialize Winsock DLL that is required, for example, here: https://github.com/bitcoin/bitcoin/blob/459272d639b9547f68000d2b9a5a0d991d477de5/src/bench/addrman.cpp#L124
Moreover, Windows docs explicitly state that WSAStartup
and WSACleanup
must be balanced:
There must be a call to
WSACleanup
for each successful call toWSAStartup
. Only the finalWSACleanup
function call performs the actual cleanup. The preceding calls simply decrement an internal reference count in the WS2_32.DLL.
That is not the case for our unit tests because the SetupNetworking()
call is a part of the BasicTestingSetup
fixture and is invoked multiple times, while ~CNetCleanup()
is invoked once only, at the end of the test binary execution.
This PR fixes Winsock DLL initialization and termination.
More docs:
- https://learn.microsoft.com/en-us/windows/win32/winsock/initializing-winsock
- https://learn.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-wsastartup
- https://learn.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-wsacleanup
Fix #28940.