Skip to content
This repository has been archived by the owner on Oct 17, 2022. It is now read-only.

Pass a host string to get_available_port. #979

Merged
merged 1 commit into from
Sep 14, 2022

Conversation

mystenmark
Copy link
Contributor

Previously, get_available_port was using "localhost", which may resolve to the ipv6 loopback instead of ipv4. We then use the obtained port in an ipv4 multiaddr in every case that was calling get_available_port()

This was probably working 99.9% of the time before by chance, since there isn't much ephemeral port contention most of the time.

Previously, get_available_port was using "localhost", which may resolve
to the ipv6 loopback instead of ipv4. We then use the obtained port in
an ipv4 multiaddr.

This was probably working 99.9% of the time before by chance, since
there isn't much ephemeral port contention most of the time.
Copy link
Contributor

@huitseeker huitseeker left a comment

Choose a reason for hiding this comment

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

Indeed, if you bind on ::1 to probe and then bind on 127.0.0.1 for actual use, you haven't actually reserved a port. Thanks!

@mystenmark I note the sui-side variant of this change at MystenLabs/sui#4525 did not excise localhost from sui's crates/sui-config/src/utils.rs's get_ephemeral_port. It would probably be wise to remove it there as well, even if sui doesn't use the same network as NW yet.

@mystenmark
Copy link
Contributor Author

Indeed, if you bind on ::1 to probe and then bind on 127.0.0.1 for actual use, you haven't actually reserved a port. Thanks!

@mystenmark I note the sui-side variant of this change at MystenLabs/sui#4525 did not excise localhost from sui's crates/sui-config/src/utils.rs's get_ephemeral_port. It would probably be wise to remove it there as well, even if sui doesn't use the same network as NW yet.

Thanks for the pointer - I know I'd seen something like that go by recently, but I couldn't figure out where it was. Will fix that as well.

@mystenmark mystenmark merged commit 271c43b into main Sep 14, 2022
@mystenmark mystenmark deleted the mlogan-use-correct-host-for-port branch September 14, 2022 00:46
@bmwill
Copy link
Contributor

bmwill commented Sep 14, 2022

We may need to rethink port reservation because we now use udp for a few interfaces and reserving a tcp port doesn't do anything to reserve a udp one. Also the same trick (the whole time_wait state with tcp) does not exist with udp unfortunately...

mwtian pushed a commit to mwtian/sui that referenced this pull request Sep 30, 2022
Previously, get_available_port was using "localhost", which may resolve
to the ipv6 loopback instead of ipv4. We then use the obtained port in
an ipv4 multiaddr.

This was probably working 99.9% of the time before by chance, since
there isn't much ephemeral port contention most of the time.

Co-authored-by: Mark Logan <mark@marklgn.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants