Repository navigation
Fix flaky refused-port socket tests - #1891
Draft
Weidong Cui (wdcui) wants to merge 6 commits into
Draft
Weidong Cui (wdcui) wants to merge 6 commits into
Weidong Cui (wdcui) wants to merge 6 commits into
Conversation
The TCP broker tests picked a port to be refused by binding an ephemeral port and freeing it before the guest connected, so a test running in parallel could take the port and the guest's connection was not refused. Keep a socket bound to the port, without listening, for the whole test: connections to it are refused, and no other socket can take it. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: f5406de6-bab4-4f3b-b232-ae238032c2c2
The Windows runner's TCP broker tests and two broker socket tests also freed a port before expecting connections to it to be refused, so a test running in parallel could take the port. As the Linux runner's tests now do, keep a socket bound to the port, without listening, for the whole test. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: f5406de6-bab4-4f3b-b232-ae238032c2c2
Several UDP tests freed a port shortly before sending to it and expecting the datagram to be refused, so a test running in parallel could take the port and receive the datagram. On Linux, keep a socket bound to the port, connected to itself, for the whole test: Linux refuses datagrams from other sockets, as for a closed port. Winsock discards them instead, so on Windows, leave the port unbound below the dynamic port range, reserved by a TCP listener on the same port, as the broker's UDP tests already did. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: f5406de6-bab4-4f3b-b232-ae238032c2c2
tcp_broker.c and the broker's loopback TCP test each checked that a connect to a refused port fails with ECONNREFUSED and reports POLLERR until the error is taken. tcp_broker_states.c checks the same, more strictly, end to end on Linux and Windows, so drop both copies, along with tcp_broker's refused-port argument. Rebuild the Windows runner's tcp_broker binary for the new arguments. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: f5406de6-bab4-4f3b-b232-ae238032c2c2
Broker unit tests checked how a connected UDP socket reports the ICMP errors its datagrams cause: a send takes a pending error, a send or connect that fails for another reason leaves it, and a socket shut down for reading still reports each error. Check these in udp_broker.c instead, where they hold on Linux and run on both broker hosts, and drop the unit tests. Keep the unit check of a failed send while the error is still with the transport, which a guest cannot arrange. Rebuild the Windows runner's udp_broker binary. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: f5406de6-bab4-4f3b-b232-ae238032c2c2
The helpers that hold a loopback port that refuses TCP connections or UDP datagrams were written three times: in the broker's socket tests and in both runners' tests, with the Windows UDP reservation twice. Move them to a test_support module behind a new test-support feature of litebox_broker_userland, which its tests and both runners' tests use. The Linux runner no longer needs socket2 for them. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: f5406de6-bab4-4f3b-b232-ae238032c2c2
Weidong Cui (wdcui)
force-pushed
the
wdcui/ulitebox/reserve-refused-ports
branch
from
November 15, 2026 20:26
8528b57 to
b6c57c7
Compare
|
🤖 SemverChecks 🤖 No breaking API changes detected Note: this does not mean API is unchanged, or even that there are no breaking changes; simply, none of the detections triggered. |
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.
This PR fixes flaky socket tests, such as AArch64's
tcp_broker.c:333failure, and removes duplicated ones. Tests picked a port to be refused by binding an ephemeral port and freeing it before use, so a test running in parallel could take it. A sharedtest-supporthelper now holds each refused port for the whole test: a bound, non-listening TCP socket; on Linux, a UDP socket connected to itself; on Windows, a UDP port outside the dynamic range. The broker's UDP refusal tests move intoudp_broker.c, which runs on Linux and Windows.