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

Run neard on localhost instead of 0.0.0.0 to prevent firewall popups on MacOS #277

Merged
merged 2 commits into from
Jun 28, 2023

Conversation

agostbiro
Copy link
Contributor

This PR fixes the problem where users were getting firewall popups when running integration tests on MacOS as described in #276.

It turns out this had two causes:

  1. neard was running on 0.0.0.0 instead of localhost.
  2. The portpicker library used to acquire free random ports was testing ports by binding to 0.0.0.0.

This PR fixes both causes.

The PR changes how neard is ran by using the more verbose run_with_options where we can specify CLI arguments to neard. We use this to specify the IP address as localhost. Previously only the port numbers were specified and neard defaulted to running on 0.0.0.0.

This PR also removes the portpicker library and provides a simple function to pick random port numbers with the OS feature where port number 0 is replaced by the OS with a random unused port. I initially considered contributing a fix to the portpicker library, but it seems unmaintained, so I thought it was a better choice to remove it from dependencies.

There are two differences between the implementation in the PR and the portpicker library:

  1. The portpicker library also checks if the port returned by the OS is a valid UDP port. The implementation in this PR forgoes that check as I think we only need TCP ports for neard.
  2. The portpicker library tries to acquire a random port by testing random numbers before falling back to requesting a port with port 0 from the OS. It's unclear why it does this. It might be a mechanism in case the OS doesn't support requesting random ports with port 0. All modern UNIX operating systems and Windows should support this, so I don't think we need such a fallback mechanism, but let me know if we do.

Copy link
Collaborator

@frol frol left a comment

Choose a reason for hiding this comment

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

@agostbiro Looks good to me! Let's get it finally fixed

@frol frol merged commit fd6e62b into near:main Jun 28, 2023
@agostbiro agostbiro deleted the 276-prevent-firewall-popups branch June 28, 2023 13:51
@frol frol mentioned this pull request Jul 5, 2023
@frol frol mentioned this pull request Oct 4, 2023
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

Successfully merging this pull request may close these issues.

2 participants