- [x] I have searched the 
[issues](https://github.com/apache/incubator-dubbo/issues) of this repository 
and believe that this is not a duplicate.
- [x] I have checked the 
[FAQ](https://github.com/apache/incubator-dubbo/blob/master/FAQ.md) of this 
repository and believe that this is not a duplicate.

### Environment

* Dubbo version: 2.6.3
* Operating System version: mac
* Java version: 1.8
* Registry: zookeeper
### Steps to reproduce this issue

1. use ReferenceConfig to get a service proxy
2. destroy ReferenceConfig
3. consumer node in Zookeeper has not been destroyed.

### Cause
1、When ReferenceProtocol refer an invoker, the consumer node is first 
registered and then subscribed to the resources of the relevant provider in 
most cases.

```

private <T> Invoker<T> doRefer(Cluster cluster, Registry registry, Class<T> 
type, URL url) {
        RegistryDirectory<T> directory = new RegistryDirectory<T>(type, url);
        directory.setRegistry(registry);
        directory.setProtocol(protocol);
        // all attributes of REFER_KEY
        Map<String, String> parameters = new HashMap<String, 
String>(directory.getUrl().getParameters());
        URL subscribeUrl = new URL(Constants.CONSUMER_PROTOCOL, 
parameters.remove(Constants.REGISTER_IP_KEY), 0, type.getName(), parameters);
        if (!Constants.ANY_VALUE.equals(url.getServiceInterface())
                && url.getParameter(Constants.REGISTER_KEY, true)) {
            
registry.register(subscribeUrl.addParameters(Constants.CATEGORY_KEY, 
Constants.CONSUMERS_CATEGORY,
                    Constants.CHECK_KEY, String.valueOf(false)));
        }
        directory.subscribe(subscribeUrl.addParameter(Constants.CATEGORY_KEY,
                Constants.PROVIDERS_CATEGORY
                        + "," + Constants.CONFIGURATORS_CATEGORY
                        + "," + Constants.ROUTERS_CATEGORY));

        Invoker invoker = cluster.join(directory);
        ProviderConsumerRegTable.registerConsumer(invoker, url, subscribeUrl, 
directory);
        return invoker;
    }

```

2、When ReferenceConfig is in destroy,  it only cancels subscription to related 
resources, but not to 
remove the consumer node.

```

@Override
    public void destroy() {
        if (isDestroyed()) {
            return;
        }
        // unsubscribe.
        try {
            if (getConsumerUrl() != null && registry != null && 
registry.isAvailable()) {
                registry.unsubscribe(getConsumerUrl(), this);
            }
        } catch (Throwable t) {
            logger.warn("unexpected error when unsubscribe service " + 
serviceKey + "from registry" + registry.getUrl(), t);
        }
        super.destroy(); // must be executed after unsubscribing
        try {
            destroyAllInvokers();
        } catch (Throwable t) {
            logger.warn("Failed to destroy service " + serviceKey, t);
        }
    }

```

[ Full content available at: 
https://github.com/apache/incubator-dubbo/issues/2546 ]
This message was relayed via gitbox.apache.org for [email protected]

Reply via email to