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

com.alibaba.dubbo.config.ServiceConfig#findConfigedPorts 多次执行 #2862

Closed
gMan1990 opened this issue Dec 2, 2018 · 3 comments
Closed

Comments

@gMan1990
Copy link

gMan1990 commented Dec 2, 2018

log:

  2018-12-02 12:04:01,669 [main] [WARN  com.alibaba.dubbo.config.AbstractConfig] com.alibaba.dubbo.config.ServiceConfig.findConfigedPorts(ServiceConfig.java:658)
     [DUBBO] Use random available port(20880) for protocol dubbo, dubbo version: 2.6.3, current host: 172.22.227.218
  2018-12-02 12:04:02,342 [main] [INFO  com.alibaba.dubbo.remoting.transport.AbstractServer] com.alibaba.dubbo.remoting.transport.AbstractServer.<init>(AbstractServer.java:65)
     [DUBBO] Start NettyServer bind /0.0.0.0:20880, export /172.22.227.218:20880, dubbo version: 2.6.3, current host: 172.22.227.218
  2018-12-02 12:04:51,998 [main] [WARN  com.alibaba.dubbo.config.AbstractConfig] com.alibaba.dubbo.config.ServiceConfig.findConfigedPorts(ServiceConfig.java:658)
     [DUBBO] Use random available port(20880) for protocol dubbo, dubbo version: 2.6.3, current host: 172.22.227.218

打印了两行Use random available port对应项目里两个提供者。
是每个提供者可以注册到不同端口还是这个被多次调用了?

@zonghaishang
Copy link
Member

@gMan1990 please provide a demo , I am using 2.6.3 version that cannot be reproduced

@gMan1990
Copy link
Author

gMan1990 commented Dec 8, 2018

@zonghaishang 不好意思,我再展开说下:

  • <dubbo:protocol name="dubbo" port="-1"
  • DUBBO_PORT_TO_BIND未配置

以dubbo-2.6.3来说:

  1. 假设写了2个Service,那么就会有2个com.alibaba.dubbo.config.spring.ServiceBean实例
@com.alibaba.dubbo.config.annotation.Service
public class Service1 ... (还有Service2)
  1. 每个实例都会执行doExportUrls方法:
    https://github.com/apache/incubator-dubbo/blob/6ce7b11f982c5f7beb2ac5897fb33d48da357ada/dubbo-config/dubbo-config-api/src/main/java/com/alibaba/dubbo/config/ServiceConfig.java#L355
private void doExportUrls() {
    List<URL> registryURLs = loadRegistries(true);
    for (ProtocolConfig protocolConfig : protocols) {
        doExportUrlsFor1Protocol(protocolConfig, registryURLs);
    }
}

假设只有一个registry和protocol,那么一个实例执行一次doExportUrlsFor1Protocol

  1. 然后执行到findConfigedPorts方法
    https://github.com/apache/incubator-dubbo/blob/6ce7b11f982c5f7beb2ac5897fb33d48da357ada/dubbo-config/dubbo-config-api/src/main/java/com/alibaba/dubbo/config/ServiceConfig.java#L635
  • 第1个实例执行到这一行:portToBind = getRandomPort(name); 得到Integer.MIN_VALUE,然后会执行getAvailablePort和putRandomPort,然后logger.warn("Use random available port("
  • 第2个实例执行到这一行:portToBind = getRandomPort(name); 得到第1个实例putRandomPort的端口,然后logger.warn("Use random available port("

就变成每个ServiceBean都打印一句logger.warn("Use random available port("了,重复打印

@tswstarplanet
Copy link
Contributor

tswstarplanet commented Dec 9, 2018

#2931

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

No branches or pull requests

3 participants