Skip to content

Fix getting a free socket on macos #420

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

reimai
Copy link

@reimai reimai commented Mar 25, 2025

Here is a new fix for a free socket on mac problem, without restry.
Turns out mac allows a socket on ANY host (. in netstat) to bind even though a socket with localhost and a same port is present in LISTENING state. This is different from linux, where such an attempt would fail with a java.net.BindException.

A way to fix this is by simply passing a localhost (or rather 127.0.0.1, to match MacPluginFrontend) to ServerSocket constructor.
I've test it on my project, and got no failures on 5 rebuilds (it used to be 2 failed bazel targets per rebuild on protoc-bridge:0.9.8).

@thesamet
Copy link
Contributor

@bell-db fyi

* which does not conflict with existing 'localhost' sockets,
* resulting in a conflict later on in MacPluginFrontend
*/
def getFreeSocket(): ServerSocket = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason not to do this on all platforms?

Copy link
Author

Choose a reason for hiding this comment

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

The only reason is me not being able to test it on Windows.

Copy link
Contributor

Choose a reason for hiding this comment

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

We have a CI job that will test it on Windows, Mac and Linux. Can you also run scalafmt so the tests will pass?

Copy link
Author

Choose a reason for hiding this comment

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

Sure, I've updated the pull request

Copy link
Author

Choose a reason for hiding this comment

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

@thesamet, could you approve the awaiting workflow?

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