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

Check assigned ports are available in SingularityExecutor #1942

Merged
merged 2 commits into from
May 23, 2019

Conversation

ssalinas
Copy link
Member

Fail fast if some other process is using a port it isn't supposed to (as opposed to letting the process start and eventually throwing something like a BindException)

@baconmania
Copy link
Contributor

🚢


private boolean isPortInUse(int port) {
try {
new Socket("127.0.0.1", port).close();
Copy link
Member

Choose a reason for hiding this comment

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

You should create a ServerSocket on 0.0.0.0 to attempt to bind the port, rather than attempting to connect to it. There are a lot of reasons the connection to the port could fail, and it could even block for a bit trying to connect which would cause this function to hang.

Additionally, there's no real guarantee in singularity that the app will bind to 127.0.0.1, it could just bind to the main IP of the host and you'd miss it, so binding 0.0.0.0 would ensure it's not listening to the port on any address.

Copy link
Member Author

Choose a reason for hiding this comment

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

good point, will switch to ServerSocket

@baconmania
Copy link
Contributor

🚢

@ssalinas ssalinas merged commit 8e348d5 into master May 23, 2019
@ssalinas ssalinas deleted the ensure_open_port branch May 23, 2019 20:13
@ssalinas ssalinas added this to the 0.23.0 milestone Jun 7, 2019
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.

3 participants