Repository navigation
Fix the flaky udp port check test - #129
Merged
Merged
Conversation
The OS only promises the udp port it hands out is free on udp. Another program can have the same number bound on tcp, which made the test fail now and then, locally and on CI. The udp test now only checks udp, and a separate test looks for a port whose tcp side is free, retrying a few times, to show the two are checked separately.
A21-devs
commented
Dec 2, 2026
A21-devs
left a comment
Owner
Author
There was a problem hiding this comment.
Read the whole diff. Test-only change, nothing in app code moves.
- The udp test no longer depends on anything outside its own socket.
- The new test still catches a mixed-up protocol in
isPortFree: if it treated a udp bind as a tcp bind, all 20 ports would read taken and it throws. returninside thetrystill runs thefinally, so the socket is closed on the success path too.
One thing I looked at and left: the tcp test's last line (closed port reads free) has the same kind of gap in theory, since another process could take the number between close and the check. That window is a few ms right after we held the port ourselves, unlike the old udp case where the other side was never ours. Not worth a loop. Looks good.
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.
Closes #78
sees a udp port that is boundbound UDP on a random port and then asserted the TCP side of the same number was free. The OS only promised the UDP side, and on Windows TCP and UDP ephemeral ports come out of the same range, so anything else on the machine holding that number on TCP failed the test. It hit my machine twice and CI once (#115).checks tcp and udp separately, binds UDP ports until it finds one whose TCP side reads free (up to 20 tries). It still fails ifisPortFreeever confused the two protocols, since then no port would pass.No change to app code.
Testing
npx vitest run tests/portCheck.test.ts(3 passed)npm run typecheck,npm test(143 passed),npm run build