Fix flaky tcp bind on Windows test runs#10387
Merged
dgarske merged 1 commit intowolfSSL:masterfrom May 5, 2026
Merged
Conversation
Windows test code pre-picked a random port via GetRandomPort() (returning a value in [49152, 65535]) before calling bind(), with no check that the port was free and no retry on collision. Under load this occasionally collided with an already-bound port and aborted the test with "tcp bind failed", producing intermittent Jenkins failures (e.g. PRB windows-test-v2 #17140 in the OCSP responder test). The Unix path already does the right thing: bind to port 0 (OS-assigned ephemeral) and read the port back via getsockname(). The same primitives exist in Winsock 1.1, so drop the USE_WINDOWS_API guard around the getsockname block in tcp_listen()/udp_accept() and remove the per-caller GetRandomPort() workarounds in the OCSP responder, server example, and the api.c / test_ossl_bio.c test sites. socklen_t is already typedef'd as int on Windows in test.h. GetRandomPort() itself is left in place since it is a static inline in a shipped public test header.
julek-wolfssl
approved these changes
May 4, 2026
Member
julek-wolfssl
left a comment
There was a problem hiding this comment.
Checks out
For TCP/IP, if the port is specified as zero, the service provider assigns a unique port to the application from the dynamic client port range. On Windows Vista and later, the dynamic client port range is a value between 49152 and 65535.
https://learn.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-bind
6 tasks
dgarske
approved these changes
May 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Windows test code pre-picked a random port via
GetRandomPort()(returning a value in [49152, 65535]) before callingbind(), with no check that the port was free and no retry on collision. Under load this occasionally collided with an already-bound port and aborted the test with "tcp bind failed", producing intermittent Jenkins failures (e.g. PRB windows-test-v2 in the OCSP responder test).The Unix path already does the right thing: bind to port 0 (OS-assigned ephemeral) and read the port back via
getsockname(). The same primitives exist in Winsock 1.1, so drop theUSE_WINDOWS_APIguard around thegetsocknameblock intcp_listen()/udp_accept()and remove the per-callerGetRandomPort()workarounds in the OCSP responder, server example, and the api.c / test_ossl_bio.c test sites.socklen_tis already typedef'd as int on Windows in test.h.GetRandomPort()itself is left in place since it is a static inline in a shipped public test header.