Skip to content
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

bind_random_port ignores OS ephemeral port range #63

Open
dmz-uk opened this issue Nov 4, 2024 · 0 comments
Open

bind_random_port ignores OS ephemeral port range #63

dmz-uk opened this issue Nov 4, 2024 · 0 comments

Comments

@dmz-uk
Copy link

dmz-uk commented Nov 4, 2024

This issue was first seen due to failed Puppet runs on a system with strict firewalling, as it uses this library. In bind_random_port, port = random(1024..65535) assumes that the ephemeral port range is 1024..65535. This is almost never the case. e.g. on a modern Linux Redhat-like system, the default range is (32768..60999) but of course can be modified by changing /proc/sys/net/ipv4/ip_local_port_range. This is not limited to being a firewall issue - modern services may bind to ports above 1024, which is especially problematic during eg a puppet run, where this random port selection may be holding open the required port during service configuration. Solution - instead of randomly choosing ports, port = 0 is defined as specifying an unused ephemeral port on at least Linux, FreeBSD, SunOS and Windows - udpsock.bind(bind_host, 0) is sufficient. There should be absolutely no need in the first place to specify a random port, or to keep trying ports until an unused one is discovered, which also does not scale particularly well on systems with heavy network usage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant