sofastack / sofa-rpc

SOFARPC is a high-performance, high-extensibility, production-level Java RPC framework.
https://www.sofastack.tech/sofa-rpc/docs/Home
Apache License 2.0
3.81k stars 1.17k forks source link

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

Open javeme opened 3 years ago

javeme commented 3 years ago

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

ujjboy commented 3 years ago

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

javeme commented 3 years ago

@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[bot] commented 2 years ago

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.

javeme commented 2 years ago

@ujjboy There is still race condition with setAdaptivePort(true): "Address already in use", could you please take a look? https://github.com/sofastack/sofa-rpc/blob/10dc5859283c1a06b2cbacf53e6f564abb488af9/core/api/src/main/java/com/alipay/sofa/rpc/common/utils/NetUtils.java#L99

stale[bot] commented 2 years ago

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.