-
Notifications
You must be signed in to change notification settings - Fork 217
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
Fixes #37413 - Let the kernel assign a TCP port in tests #893
Fixes #37413 - Let the kernel assign a TCP port in tests #893
Conversation
367c40d
to
83c33ed
Compare
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.
Very nice, thanks. Fixes the issue with docker.
end | ||
Timeout.timeout(2) do | ||
sleep(0.1) until can_connect?('localhost', @settings.send("#{protocol}_port")) | ||
sleep(0.1) until can_connect?('localhost', @settings["#{protocol}_port"]) |
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.
Technically this change isn't needed, but it feels more consistent if we're also setting it as a hash on line 49.
end | ||
end | ||
|
||
def can_connect?(host, port) | ||
return false if port == 0 |
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.
This took me a while to figure out, but the server is started in a thread, so the port isn't immediately set.
This binds on port 0, which lets the kernel decide which port to use. The port is then read back from the listener. Because the kernel knows which ports it's allowed to bind to, it removes the risk of a failure due to collisions or policies.
83c33ed
to
bf8b44f
Compare
This binds on port 0, which lets the kernel decide which port to use. The port is then read back from the listener. Because the kernel knows which ports it's allowed to bind to, it removes the risk of a failure due to collisions or policies.