-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
change(tests): use OS-assigned unallocated ports for getting random known ports #5607
Conversation
Co-authored-by: teor <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm happy to try this, and if it ends up not working on Windows, or in some tests, we can go back to using a numerically random port selection.
But every test it does work for is one less test that will randomly fail.
It's impossible to do this check in a reliable, cross-platform way.
Here's some background for that comment:
Windows sometimes waits a few minutes before allowing port reuse:
https://serverfault.com/questions/541070/linux-tcp-source-port-reuse-and-delay/609829#609829
On Linux and macOS, it would be easier if we set the SO_REUSEADDR option on Zebra's ports, but that's impossible for tokio and std Rust ports, because they don't expose that option. (Maybe they've improved the API since?)
https://programmer.group/so_reuseaddr-and-so_reuseport-socket-options-for-tcp-ip-programming.html
It's a 2-minute default Tokio seems to support We can close this now or put it under |
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #5607 +/- ##
==========================================
+ Coverage 78.67% 78.79% +0.11%
==========================================
Files 305 305
Lines 38211 38320 +109
==========================================
+ Hits 30064 30195 +131
+ Misses 8147 8125 -22 |
I think Rust std added it recently as well? |
It seems to work, so let's use the same Then we can keep the old code and use it for Windows. |
That explains why this worked. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, but let's merge it separately from #5589, in case we need to revert?
@Mergifyio update |
✅ Branch has been successfully updated |
Motivation
The
random_known_port
may return an allocated port, causing a test error.This PR reduces the likelihood of those errors by having the OS find a port that is unallocated at the time that
random_known_port
is called, and by broadening the range of possible ports.Solution
Review
Reviewer Checklist