Skip to content

Fix flaky tcp bind on Windows test runs#10387

Merged
dgarske merged 1 commit intowolfSSL:masterfrom
Frauschi:fix-windows-tcp-bind-flaky
May 5, 2026
Merged

Fix flaky tcp bind on Windows test runs#10387
dgarske merged 1 commit intowolfSSL:masterfrom
Frauschi:fix-windows-tcp-bind-flaky

Conversation

@Frauschi
Copy link
Copy Markdown
Contributor

@Frauschi Frauschi commented May 4, 2026

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 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.

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.
@Frauschi Frauschi self-assigned this May 4, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 4, 2026

MemBrowse Memory Report

No memory changes detected for:

@Frauschi Frauschi assigned wolfSSL-Bot and unassigned Frauschi May 4, 2026
@Frauschi Frauschi requested a review from julek-wolfssl May 4, 2026 12:21
Copy link
Copy Markdown
Member

@julek-wolfssl julek-wolfssl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@dgarske dgarske merged commit e38a120 into wolfSSL:master May 5, 2026
415 checks passed
@Frauschi Frauschi deleted the fix-windows-tcp-bind-flaky branch May 5, 2026 19:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants