apache / dubbo

The java implementation of Apache Dubbo. An RPC and microservice framework.
https://dubbo.apache.org/
Apache License 2.0
40.53k stars 26.44k forks source link

[Bug] Triple protocol reExport failed when overriding provider's url #14430

Open benko233 opened 4 months ago

benko233 commented 4 months ago

Pre-check

Search before asking

Apache Dubbo Component

Java SDK (apache/dubbo)

Dubbo Version

3.2.14

Steps to reproduce this issue

step 1. add dynamic configuration like this

configVersion: v2.7
configs:
- addresses:
  - xxxx:xxxx
  parameters:
    disabled: true
  side: provider
enabled: true
key: xxxx
scope: application

step 2. Provider throws an IllegalStateException in TripleProtocol#export because serviceKey contains version while interfaceName does not. image

What you expected to happen

Why compare serviceKey with interfaceName here? Why not compare serviceKey with provious's serviceKey?

Anything else

2024-07-15 09:51:00,528 [ZookeeperDynamicConfiguration-thread-1] ERROR NodeCache: - Calling listener
java.lang.IllegalStateException: Already exists an invoker[\*\*\*\*\*\*\*\*] on path[\*\*\*\*\*\*\*\*], failed to add invoker[\*\*\*\*\*\*\*\*] , please use unique serviceKey.
    at org.apache.dubbo.rpc.protocol.tri.TripleProtocol.export(TripleProtocol.java:126) ~[dubbo-3.2.14.jar:3.2.14]
    at org.apache.dubbo.qos.protocol.QosProtocolWrapper.export(QosProtocolWrapper.java:79) ~[dubbo-3.2.14.jar:3.2.14]
    at org.apache.dubbo.rpc.protocol.ProtocolSecurityWrapper.export(ProtocolSecurityWrapper.java:84) ~[dubbo-3.2.14.jar:3.2.14]
    at org.apache.dubbo.rpc.protocol.ProtocolListenerWrapper.export(ProtocolListenerWrapper.java:77) ~[dubbo-3.2.14.jar:3.2.14]
    at org.apache.dubbo.rpc.cluster.filter.ProtocolFilterWrapper.export(ProtocolFilterWrapper.java:61) ~[dubbo-3.2.14.jar:3.2.14]
    at org.apache.dubbo.rpc.protocol.ProtocolSerializationWrapper.export(ProtocolSerializationWrapper.java:50) ~[dubbo-3.2.14.jar:3.2.14]
    at org.apache.dubbo.rpc.protocol.InvokerCountWrapper.export(InvokerCountWrapper.java:42) ~[dubbo-3.2.14.jar:3.2.14]
    at org.apache.dubbo.rpc.Protocol$Adaptive.export(Protocol$Adaptive.java) ~[dubbo-3.2.14.jar:3.2.14]
    at org.apache.dubbo.registry.integration.RegistryProtocol.reExport(RegistryProtocol.java:381) ~[dubbo-3.2.14.jar:3.2.14]
    at org.apache.dubbo.registry.integration.RegistryProtocol$OverrideListener.doOverrideIfNecessary(RegistryProtocol.java:874) ~[dubbo-3.2.14.jar:3.2.14]
    at org.apache.dubbo.registry.integration.RegistryProtocol$ProviderConfigurationListener.lambda$notifyOverrides$0(RegistryProtocol.java:982) ~[dubbo-3.2.14.jar:3.2.14]
    at java.util.concurrent.ConcurrentHashMap$ValuesView.forEach(ConcurrentHashMap.java:4707) ~[?:1.8.0_302]
    at org.apache.dubbo.registry.integration.RegistryProtocol$ProviderConfigurationListener.notifyOverrides(RegistryProtocol.java:980) ~[dubbo-3.2.14.jar:3.2.14]
    at org.apache.dubbo.registry.integration.AbstractConfiguratorListener.process(AbstractConfiguratorListener.java:104) ~[dubbo-3.2.14.jar:3.2.14]
    at org.apache.dubbo.configcenter.support.zookeeper.ZookeeperDataListener.lambda$dataChanged$0(ZookeeperDataListener.java:80) ~[dubbo-3.2.14.jar:3.2.14]
    at java.util.concurrent.CopyOnWriteArrayList.forEach(CopyOnWriteArrayList.java:895) ~[?:1.8.0_302]
    at java.util.concurrent.CopyOnWriteArraySet.forEach(CopyOnWriteArraySet.java:404) ~[?:1.8.0_302]
    at org.apache.dubbo.configcenter.support.zookeeper.ZookeeperDataListener.dataChanged(ZookeeperDataListener.java:80) ~[dubbo-3.2.14.jar:3.2.14]
    at org.apache.dubbo.remoting.zookeeper.curator5.Curator5ZookeeperClient$NodeCacheListenerImpl.nodeChanged(Curator5ZookeeperClient.java:442) ~[dubbo-3.2.14.jar:3.2.14]
    at org.apache.curator.framework.recipes.cache.NodeCache.lambda$setNewData$0(NodeCache.java:323) ~[curator-recipes-5.3.0.jar:5.3.0]
    at org.apache.curator.framework.listen.MappingListenerManager.lambda$forEach$0(MappingListenerManager.java:92) ~[curator-framework-5.3.0.jar:5.3.0]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) ~[?:1.8.0_302]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) ~[?:1.8.0_302]
    at java.lang.Thread.run(Thread.java:748) ~[?:1.8.0_302]

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

Code of Conduct

benko233 commented 1 month ago

If provide version, the invoker in pathResolver must have non-equal serviceKey and interfaceName. At this scenario, all overridings fail. I think more reasonable to compare url.getServiceKey() with previous.getUrl().getServiceKey() at TripleProtocol#export.

    @Override
    public <T> Exporter<T> export(Invoker<T> invoker) throws RpcException {
    // ...
    Invoker<?> previous = pathResolver.add(url.getServiceKey(), invoker);
        if (previous != null) {
            if (url.getServiceKey().equals(previous.getUrl().getServiceKey())) {
                logger.info("Already exists an invoker[" + previous.getUrl() + "] on path[" + url.getServiceKey()
                    + "], dubbo will override with invoker[" + url + "]");
            } else {
                throw new IllegalStateException("Already exists an invoker[" + previous.getUrl() + "] on path[" +
                    url.getServiceKey() + "], failed to add invoker[" + url +
                    "] , please use unique serviceKey.");
            }
        }
    // ...
    }
AlbumenJ commented 1 month ago

Currently, Triple not support reExport. We should fix it in the future