dubbo icon indicating copy to clipboard operation
dubbo copied to clipboard

[Bug] The actual number of connections established is twice what I configured

Open lpcy opened this issue 1 year ago • 3 comments

Pre-check

  • [X] I am sure that all the content I provide is in English.

Search before asking

  • [X] I had searched in the issues and found no similar issues.

Apache Dubbo Component

Java SDK (apache/dubbo)

Dubbo Version

Dubbo Java 3.2.5, JDK 1.8, Linux

Steps to reproduce this issue

provider config(spring xml)

 <dubbo:application name="dubbo-provider"  />
 <dubbo:registry protocol="zookeeper" file="registry.cache" address="127.0.0.1:2181" />
 <dubbo:protocol name="dubbo" port="2087" accesslog="true"/>
<dubbo:service interface="api.service.IRun" ref="runImpl" timeout="600000" cluster="failfast"/>

consumer config(spring xml)

<dubbo:application name="dubbo-consumer"  />
<dubbo:registry protocol="zookeeper" file="registry.cache" address="127.0.0.1:2181" />
<dubbo:protocol name="dubbo" port="2088" accesslog="true"/>
<dubbo:reference id="run" interface="api.service.IRun" connections="7"/>

What you expected to happen

After upgrading from Dubbo2 to Dubbo3.2.5, with the same configuration, the actual number of connections is twice normal, meaning that a consumer sends 14 connections to a provider.

Anything else

No response

Are you willing to submit a pull request to fix on your own?

  • [ ] Yes I am willing to submit a pull request on my own!

Code of Conduct

lpcy avatar Apr 25 '24 06:04 lpcy

i can see the number of connections in DubboProtocol#getClients and it's normal.can u provide more information?i can't reproduce this bug.

walkinggo avatar Apr 29 '24 15:04 walkinggo

i can see the number of connections in DubboProtocol#getClients and it's normal.can u provide more information?i can't reproduce this bug.

I found that DubboProtocol#getClients will be called twice: First:

getClients:419, DubboProtocol (org.apache.dubbo.rpc.protocol.dubbo)
protocolBindingRefer:412, DubboProtocol (org.apache.dubbo.rpc.protocol.dubbo)
......
toInvokers:430, RegistryDirectory (org.apache.dubbo.registry.integration)
refreshInvoker:292, RegistryDirectory (org.apache.dubbo.registry.integration)
refreshOverrideAndInvoker:233, RegistryDirectory (org.apache.dubbo.registry.integration)
notify:209, RegistryDirectory (org.apache.dubbo.registry.integration)
notify:533, AbstractRegistry (org.apache.dubbo.registry.support)
doNotify:373, FailbackRegistry (org.apache.dubbo.registry.support)
notify:365, FailbackRegistry (org.apache.dubbo.registry.support)
doSubscribe:241, ZookeeperRegistry (org.apache.dubbo.registry.zookeeper)
subscribe:300, FailbackRegistry (org.apache.dubbo.registry.support)
......
refreshInterfaceInvoker:464, MigrationInvoker (org.apache.dubbo.registry.client.migration)
migrateToApplicationFirstInvoker:245, MigrationInvoker (org.apache.dubbo.registry.client.migration)
refreshInvoker:76, MigrationRuleHandler (org.apache.dubbo.registry.client.migration)
doMigrate:60, MigrationRuleHandler (org.apache.dubbo.registry.client.migration)
......
createInvoker:615, ReferenceConfig (org.apache.dubbo.config)
createProxy:461, ReferenceConfig (org.apache.dubbo.config)
init:348, ReferenceConfig (org.apache.dubbo.config)
......

second:

getClients:419, DubboProtocol (org.apache.dubbo.rpc.protocol.dubbo)
protocolBindingRefer:412, DubboProtocol (org.apache.dubbo.rpc.protocol.dubbo)
......
toInvokers:419, ServiceDiscoveryRegistryDirectory (org.apache.dubbo.registry.client)
refreshInvoker:313, ServiceDiscoveryRegistryDirectory (org.apache.dubbo.registry.client)
refreshOverrideAndInvoker:197, ServiceDiscoveryRegistryDirectory (org.apache.dubbo.registry.client)
notify:189, ServiceDiscoveryRegistryDirectory (org.apache.dubbo.registry.client)
addListenerAndNotify:236, ServiceInstancesChangedListener (org.apache.dubbo.registry.client.event.listener)
subscribeURLs:330, ServiceDiscoveryRegistry (org.apache.dubbo.registry.client)
doSubscribe:227, ServiceDiscoveryRegistry (org.apache.dubbo.registry.client)
subscribe:189, ServiceDiscoveryRegistry (org.apache.dubbo.registry.client)
subscribe:88, ListenerRegistryWrapper (org.apache.dubbo.registry)
subscribe:184, DynamicDirectory (org.apache.dubbo.registry.integration)
subscribe:140, ServiceDiscoveryRegistryDirectory (org.apache.dubbo.registry.client)
doCreateInvoker:629, RegistryProtocol (org.apache.dubbo.registry.integration)
getServiceDiscoveryInvoker:65, InterfaceCompatibleRegistryProtocol (org.apache.dubbo.registry.integration)
refreshServiceDiscoveryInvoker:440, MigrationInvoker (org.apache.dubbo.registry.client.migration)
migrateToApplicationFirstInvoker:246, MigrationInvoker (org.apache.dubbo.registry.client.migration)
refreshInvoker:76, MigrationRuleHandler (org.apache.dubbo.registry.client.migration)
doMigrate:60, MigrationRuleHandler (org.apache.dubbo.registry.client.migration)
onRefer:249, MigrationRuleListener (org.apache.dubbo.registry.client.migration)
interceptInvoker:594, RegistryProtocol (org.apache.dubbo.registry.integration)
......
createInvoker:615, ReferenceConfig (org.apache.dubbo.config)
createProxy:461, ReferenceConfig (org.apache.dubbo.config)
init:348, ReferenceConfig (org.apache.dubbo.config)

The key method is MigrationInvoker#migrateToApplicationFirstInvoker. The getClients method will be called separately once:

    @Override
    public void migrateToApplicationFirstInvoker(MigrationRule newRule) {
        CountDownLatch latch = new CountDownLatch(0);
        refreshInterfaceInvoker(latch);
        refreshServiceDiscoveryInvoker(latch);

        // directly calculate preferred invoker, will not wait until address notify
        // calculation will re-occurred when address notify later
        calcPreferredInvoker(newRule);
    }

lpcy avatar Apr 30 '24 07:04 lpcy

In version 3.x of Dubbo, to maintain compatibility with the older 2.x versions, Dubbo adopted a dual registration method during service migration, registering services both at the interface level and the application level. This is why the number of connections appears to be doubled. you can see the explain in chinese version or english version . You can find the details of the interface-level services in the ZooKeeper path /dubbo/com.example.ProductService/providers, and the details of the application-level services under the ZooKeeper path /dubbo/metadata/ProductApp.In ZooKeeper, you can indeed see that the specific number of connections is 7.

walkinggo avatar Apr 30 '24 15:04 walkinggo

Please close this pr as completed @AlbumenJ

wcy666103 avatar Jun 05 '24 05:06 wcy666103