Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Windows crash at startup introduced by MR !786
Summary --- MR !786 introduced a hard crash at startup for Windows because it relied on the gethostaddr() facility which, on Windows, is not available at all until after WSAStartup() is called. The crash produced the following error when running on a real Windows system (not WINE), and it was due to the fact that we are now doing LookupName() which calls getaddrinfo() in winsock before WSAStartup() was called. Here is the error: ``` D:\bchn>bin\bitcoind.exe -hh terminate called after throwing an instance of 'std::invalid_argument' what(): Unable to parse numeric-IP:port pair: 2.37.183.149:8333 This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information. ``` Since we only ever call WSAStartup() once in this codebase, and always with the same exact 2,2 WSA version request, it is safe to call this at any time. Calling it earlier or later has no negative effect -- all of the other things this codebase does on Windows has no effect on this DLL's initialization. The reason this restriction exists in Windows is so that the same DLL can support multiple "personalities" or APIs depending on the version requested at runtime by the application. On every other platform no such restriction exists. WSAStartup() is used by applications to declare the version of the winsock API they want to use. Test Plan --- 1. Build bitcoind without this commit, run it on a real Windows system (not Wine), verify that it crashes on startup `bitcoind -hh` should fail. 2. Build bitcoind with this commit, verify that it does not crash and executes normally. Bonus: Start an IBD on Windows just to test out networking.
- Loading branch information