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

ephemeral node ports #35

Closed
AlexCheema opened this issue Jul 19, 2024 · 0 comments
Closed

ephemeral node ports #35

AlexCheema opened this issue Jul 19, 2024 · 0 comments

Comments

@AlexCheema
Copy link
Contributor

This would fix a lot of issues, particularly around peers being dropped when they lose connection. We currently have no way to know if a new node was started on the same port or if the old node is still running. This would also fix #14 and #15

This kind of thing:

async def find_free_port(start_port=49152, end_port=65535, max_attempts=100):
    """Find a free port in the ephemeral port range."""
    for _ in range(max_attempts):
        port = random.randint(start_port, end_port)
        try:
            with closing(socket.socket(socket.AF_INET, socket.SOCK_DGRAM)) as sock:
                sock.bind(('', port))
                return port
        except OSError:
            continue
    raise RuntimeError(f"Unable to find a free port after {max_attempts} attempts")
dan-online pushed a commit to bytebolt-media/exo that referenced this issue Aug 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant