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

Can't get actual port from ServerConfig when using random port #1022

Open
javeme opened this issue Mar 18, 2021 · 5 comments
Open

Can't get actual port from ServerConfig when using random port #1022

javeme opened this issue Mar 18, 2021 · 5 comments
Labels
question Further information is requested remind To be further discussed

Comments

@javeme
Copy link

javeme commented Mar 18, 2021

Describe the bug

A clear and concise description of what the bug is.

Expected behavior

Expect to add port() method to com.alipay.sofa.rpc.server.Server interface, we can get the actual port from server implementation.

Actual behavior

ServerConfig.getPort() returns 0

Steps to reproduce

new ServerConfig().setPort(0)
                  .setHost("127.0.0.1")
                  .setProtocol("bolt")

Environment

  • SOFARPC version: 5.7.6
  • JVM version : java8
  • OS version : mac
  • Maven version:
  • IDE version: eclipse
@sofastack-bot sofastack-bot bot added the question Further information is requested label Mar 18, 2021
@ujjboy
Copy link
Member

ujjboy commented Mar 18, 2021

@javeme You can use new ServerConfig().setAdaptivePort(true); and invoke serverConfig.getPort() after the server started.

@javeme
Copy link
Author

javeme commented Mar 19, 2021

@ujjboy Thank you for your reply.
I tried setAdaptivePort(true) after got your reply, but when multiple jobs(like YARN container) were started at the same time, they may still compete for the same port, resulting in a race error "Address already in use".

In this scenario, it would be a perfect solution if sofa-rpc can support random port.

@stale
Copy link

stale bot commented Feb 8, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix This will not be worked on label Feb 8, 2022
@javeme
Copy link
Author

javeme commented Feb 8, 2022

@ujjboy There is still race condition with setAdaptivePort(true): "Address already in use", could you please take a look?

public static int getAvailablePort(String host, int port, int maxPort) {

@stale stale bot removed the wontfix This will not be worked on label Feb 8, 2022
@stale
Copy link

stale bot commented Apr 9, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix This will not be worked on label Apr 9, 2022
@EvenLjj EvenLjj added remind To be further discussed and removed wontfix This will not be worked on labels Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested remind To be further discussed
Projects
None yet
Development

No branches or pull requests

3 participants