<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have searched the <a href="https://github.com/apache/dubbo/issues">issues</a> of this repository and believe that this is not a duplicate.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have checked the <a href="https://github.com/apache/dubbo/blob/master/FAQ.md">FAQ</a> of this repository and believe that this is not a duplicate.</li>
</ul>
<h3 dir="auto">Environment</h3>
<ul dir="auto">
<li>Dubbo version: <code class="notranslate">2.7.3</code></li>
<li>Operating System version: <code class="notranslate">Centos 7</code></li>
<li>Java version: <code class="notranslate">1.8</code></li>
<li>Spring Boot version: <code class="notranslate">2.1.7.RELEASE</code></li>
<li>Spring Cloud version: <code class="notranslate">Greenwich.SR5</code></li>
<li>Nacos version: <code class="notranslate">1.3.1</code></li>
<li>Nacos集群、Dubbo生产者、Dubbo消费者均部署在K8s环境中</li>
</ul>
<h3 dir="auto">Steps to reproduce this issue</h3>
<ol dir="auto">
<li>正常启动Nacos集群、生产者、消费者</li>
<li>滚动更新生产者服务，确保新IP已注册，老的IP已执行Unregister</li>
<li>查看消费者日志，出现异常。但是此时可以正常调用生产者服务</li>
</ol>
<h3 dir="auto">Expected Result</h3>
<ul dir="auto">
<li>消费者可以正常切换到生产者新的IP</li>
</ul>
<h3 dir="auto">Actual Result</h3>
<ol dir="auto">
<li>正常启动Nacos集群、生产者、消费者</li>
<li>滚动更新生产者服务，确保新IP已注册，老的IP已执行Unregister</li>
</ol>
<ul dir="auto">
<li>
<p dir="auto">新的IP已注册<br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/12381829/87759110-505dad00-c840-11ea-8735-b16fd54403a4.png"><img src="https://user-images.githubusercontent.com/12381829/87759110-505dad00-c840-11ea-8735-b16fd54403a4.png" alt="image" style="max-width: 100%;"></a></p>
</li>
<li>
<p dir="auto">老的IP已执行Unregister<br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/12381829/87759186-6ec3a880-c840-11ea-9b5d-daf69adcc6f3.png"><img src="https://user-images.githubusercontent.com/12381829/87759186-6ec3a880-c840-11ea-9b5d-daf69adcc6f3.png" alt="image" style="max-width: 100%;"></a><br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/12381829/87759220-826f0f00-c840-11ea-955d-bf43525efb23.png"><img src="https://user-images.githubusercontent.com/12381829/87759220-826f0f00-c840-11ea-955d-bf43525efb23.png" alt="image" style="max-width: 100%;"></a></p>
</li>
</ul>
<ol start="3" dir="auto">
<li>
<p dir="auto">查看消费者日志，发现报错如下<br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/12381829/87760083-d29aa100-c841-11ea-9484-7abfa754d824.png"><img src="https://user-images.githubusercontent.com/12381829/87760083-d29aa100-c841-11ea-9484-7abfa754d824.png" alt="image" style="max-width: 100%;"></a><br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/12381829/87760108-daf2dc00-c841-11ea-9df0-3e5303f17f25.png"><img src="https://user-images.githubusercontent.com/12381829/87760108-daf2dc00-c841-11ea-9df0-3e5303f17f25.png" alt="image" style="max-width: 100%;"></a><br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/12381829/87760132-e6460780-c841-11ea-80b1-c8da2a5ca0d2.png"><img src="https://user-images.githubusercontent.com/12381829/87760132-e6460780-c841-11ea-80b1-c8da2a5ca0d2.png" alt="image" style="max-width: 100%;"></a></p>
</li>
<li>
<p dir="auto">几分钟后，会循环打印下面截图所示错误日志<br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/12381829/87760015-beef3a80-c841-11ea-952e-5701477bd81b.png"><img src="https://user-images.githubusercontent.com/12381829/87760015-beef3a80-c841-11ea-952e-5701477bd81b.png" alt="image" style="max-width: 100%;"></a></p>
</li>
</ol>
<p dir="auto">If there is an exception, please attach the exception trace:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="2020-07-17 14:48:09,908 [com.alibaba.nacos.naming.client.listener] ERROR [c.a.c.d.s.DubboMetadataServi
ceInvocationHandler] DubboMetadataServiceInvocationHandler.java:59 - [failed 5 times] Failed to invoke
 the method getExportedURLs in the service org.apache.dubbo.rpc.service.GenericService. Tried 3 times 
of the providers [172.30.2.17:20880] (1/1) from the registry localhost:9090 on the consumer 172.30.3.1
59 using the dubbo version 2.7.3. Last error is: Failed to invoke remote method: $invoke, provider: du
bbo://172.30.2.17:20880/com.alibaba.cloud.dubbo.service.DubboMetadataService?anyhost=true&amp;application=
com-petkit-message-service&amp;bind.ip=172.30.2.17&amp;bind.port=20880&amp;check=false&amp;deprecated=false&amp;dubbo=2.0.
2&amp;dynamic=true&amp;generic=true&amp;group=com-petkit-sms-service&amp;interface=com.alibaba.cloud.dubbo.service.Dub
boMetadataService&amp;lazy=false&amp;methods=getAllServiceKeys,getServiceRestMetadata,getExportedURLs,getAllEx
portedURLs&amp;pid=6&amp;qos.enable=false&amp;register=true&amp;register.ip=172.30.3.159&amp;release=2.7.3&amp;remote.applicat
ion=com-petkit-sms-service&amp;revision=2.1.1.RELEASE&amp;side=consumer&amp;sticky=false&amp;timestamp=1594901114548&amp;v
ersion=1.0.0, cause: message can not send, because channel is closed . url:dubbo://172.30.2.17:20880/c
om.alibaba.cloud.dubbo.service.DubboMetadataService?anyhost=true&amp;application=com-petkit-message-servic
e&amp;bind.ip=172.30.2.17&amp;bind.port=20880&amp;check=false&amp;codec=dubbo&amp;deprecated=false&amp;dubbo=2.0.2&amp;dynamic=tru
e&amp;generic=true&amp;group=com-petkit-sms-service&amp;heartbeat=60000&amp;interface=com.alibaba.cloud.dubbo.service.
DubboMetadataService&amp;lazy=false&amp;methods=getAllServiceKeys,getServiceRestMetadata,getExportedURLs,getAl
lExportedURLs&amp;pid=6&amp;qos.enable=false&amp;register=true&amp;register.ip=172.30.3.159&amp;release=2.7.3&amp;remote.appli
cation=com-petkit-sms-service&amp;revision=2.1.1.RELEASE&amp;side=consumer&amp;sticky=false&amp;timestamp=159490111454
8&amp;version=1.0.0
org.apache.dubbo.rpc.RpcException: Failed to invoke the method getExportedURLs in the service org.apac
he.dubbo.rpc.service.GenericService. Tried 3 times of the providers [172.30.2.17:20880] (1/1) from the
 registry localhost:9090 on the consumer 172.30.3.159 using the dubbo version 2.7.3. Last error is: Fa
iled to invoke remote method: $invoke, provider: dubbo://172.30.2.17:20880/com.alibaba.cloud.dubbo.ser
vice.DubboMetadataService?anyhost=true&amp;application=com-petkit-message-service&amp;bind.ip=172.30.2.17&amp;bind
.port=20880&amp;check=false&amp;deprecated=false&amp;dubbo=2.0.2&amp;dynamic=true&amp;generic=true&amp;group=com-petkit-sms-se
rvice&amp;interface=com.alibaba.cloud.dubbo.service.DubboMetadataService&amp;lazy=false&amp;methods=getAllServiceK
eys,getServiceRestMetadata,getExportedURLs,getAllExportedURLs&amp;pid=6&amp;qos.enable=false&amp;register=true&amp;reg
ister.ip=172.30.3.159&amp;release=2.7.3&amp;remote.application=com-petkit-sms-service&amp;revision=2.1.1.RELEASE&amp;s
ide=consumer&amp;sticky=false&amp;timestamp=1594901114548&amp;version=1.0.0, cause: message can not send, because 
channel is closed . url:dubbo://172.30.2.17:20880/com.alibaba.cloud.dubbo.service.DubboMetadataService
?anyhost=true&amp;application=com-petkit-message-service&amp;bind.ip=172.30.2.17&amp;bind.port=20880&amp;check=false&amp;c
odec=dubbo&amp;deprecated=false&amp;dubbo=2.0.2&amp;dynamic=true&amp;generic=true&amp;group=com-petkit-sms-service&amp;heartbe
at=60000&amp;interface=com.alibaba.cloud.dubbo.service.DubboMetadataService&amp;lazy=false&amp;methods=getAllServi
ceKeys,getServiceRestMetadata,getExportedURLs,getAllExportedURLs&amp;pid=6&amp;qos.enable=false&amp;register=true&amp;
register.ip=172.30.3.159&amp;release=2.7.3&amp;remote.application=com-petkit-sms-service&amp;revision=2.1.1.RELEAS
E&amp;side=consumer&amp;sticky=false&amp;timestamp=1594901114548&amp;version=1.0.0
        at org.apache.dubbo.rpc.cluster.support.FailoverClusterInvoker.doInvoke(FailoverClusterInvoker.java:113)
        at org.apache.dubbo.rpc.cluster.support.AbstractClusterInvoker.invoke(AbstractClusterInvoker.java:248)
        at org.apache.dubbo.rpc.cluster.support.wrapper.MockClusterInvoker.invoke(MockClusterInvoker.java:78)
        at org.apache.dubbo.rpc.proxy.InvokerInvocationHandler.invoke(InvokerInvocationHandler.java:55)
        at org.apache.dubbo.common.bytecode.proxy6.$invoke(proxy6.java)
        at com.alibaba.cloud.dubbo.service.DubboMetadataServiceInvocationHandler.invoke(DubboMetadataServiceInvocationHandler.java:54)
        at com.sun.proxy.$Proxy138.getExportedURLs(Unknown Source)
        at com.alibaba.cloud.dubbo.registry.AbstractSpringCloudRegistry.getExportedURLs(AbstractSpringCloudRegistry.java:338)
        at com.alibaba.cloud.dubbo.registry.AbstractSpringCloudRegistry.subscribeDubboServiceURL(AbstractSpringCloudRegistry.java:272)
        at com.alibaba.cloud.dubbo.registry.AbstractSpringCloudRegistry$1.onApplicationEvent(AbstractSpringCloudRegistry.java:195)
        at com.alibaba.cloud.dubbo.registry.AbstractSpringCloudRegistry$1.onApplicationEvent(AbstractSpringCloudRegistry.java:188)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
        at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:402)
        at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:359)
        at com.alibaba.cloud.dubbo.autoconfigure.DubboServiceDiscoveryAutoConfiguration.dispatchServiceInstancesChangedEvent(DubboServiceDiscoveryAutoConfiguration.java:168)
        at com.alibaba.cloud.dubbo.autoconfigure.DubboServiceDiscoveryAutoConfiguration.access$200(DubboServiceDiscoveryAutoConfiguration.java:105)
        at com.alibaba.cloud.dubbo.autoconfigure.DubboServiceDiscoveryAutoConfiguration$NacosConfiguration.lambda$subscribeEventListener$1(DubboServiceDiscoveryAutoConfiguration.java:551)
        at com.alibaba.nacos.client.naming.core.EventDispatcher$Notifier.run(EventDispatcher.java:128)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
Caused by: org.apache.dubbo.remoting.RemotingException: message can not send, because channel is closed . url:dubbo://172.30.2.17:20880/com.alibaba.cloud.dubbo.service.DubboMetadataService?anyhost=true&amp;application=com-petkit-message-service&amp;bind.ip=172.30.2.17&amp;bind.port=20880&amp;check=false&amp;codec=dubbo&amp;deprecated=false&amp;dubbo=2.0.2&amp;dynamic=true&amp;generic=true&amp;group=com-petkit-sms-service&amp;heartbeat=60000&amp;interface=com.alibaba.cloud.dubbo.service.DubboMetadataService&amp;lazy=false&amp;methods=getAllServiceKeys,getServiceRestMetadata,getExportedURLs,getAllExportedURLs&amp;pid=6&amp;qos.enable=false&amp;register=true&amp;register.ip=172.30.3.159&amp;release=2.7.3&amp;remote.application=com-petkit-sms-service&amp;revision=2.1.1.RELEASE&amp;side=consumer&amp;sticky=false&amp;timestamp=1594901114548&amp;version=1.0.0
        at org.apache.dubbo.remoting.transport.AbstractClient.send(AbstractClient.java:175)
        at org.apache.dubbo.remoting.transport.AbstractPeer.send(AbstractPeer.java:53)
        at org.apache.dubbo.remoting.exchange.support.header.HeaderExchangeChannel.request(HeaderExchangeChannel.java:118)
        at org.apache.dubbo.remoting.exchange.support.header.HeaderExchangeClient.request(HeaderExchangeClient.java:84)
        at org.apache.dubbo.rpc.protocol.dubbo.ReferenceCountExchangeClient.request(ReferenceCountExchangeClient.java:80)
        at org.apache.dubbo.rpc.protocol.dubbo.DubboInvoker.doInvoke(DubboInvoker.java:97)
        at org.apache.dubbo.rpc.protocol.AbstractInvoker.invoke(AbstractInvoker.java:155)
        at org.apache.dubbo.rpc.protocol.AsyncToSyncInvoker.invoke(AsyncToSyncInvoker.java:52)
        at org.apache.dubbo.rpc.listener.ListenerInvokerWrapper.invoke(ListenerInvokerWrapper.java:78)
        at org.apache.dubbo.rpc.filter.GenericImplFilter.invoke(GenericImplFilter.java:119)
        at org.apache.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:82)
        at org.apache.dubbo.monitor.support.MonitorFilter.invoke(MonitorFilter.java:92)
        at org.apache.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:82)
        at org.apache.dubbo.rpc.protocol.dubbo.filter.FutureFilter.invoke(FutureFilter.java:54)
        at org.apache.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:82)
        at org.apache.dubbo.rpc.filter.ConsumerContextFilter.invoke(ConsumerContextFilter.java:58)
        at org.apache.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:82)
        at org.apache.dubbo.rpc.protocol.ProtocolFilterWrapper$CallbackRegistrationInvoker.invoke(ProtocolFilterWrapper.java:157)
        at org.apache.dubbo.rpc.protocol.InvokerWrapper.invoke(InvokerWrapper.java:56)
        at org.apache.dubbo.rpc.cluster.support.FailoverClusterInvoker.doInvoke(FailoverClusterInvoker.java:82)
        ... 22 common frames omitted
2020-07-17 14:48:42,077 [dubbo-client-idleCheck-thread-1] INFO  [o.a.d.r.exchange.support.header.ReconnectTimerTask] ReconnectTimerTask.java:48 -  [DUBBO] Initial connection to HeaderExchangeClient [channel=org.apache.dubbo.remoting.transport.netty4.NettyClient [172.30.3.159:0 -&gt; /172.30.2.17:20880]], dubbo version: 2.7.3, current host: 172.30.3.159
2020-07-17 14:48:45,084 [dubbo-client-idleCheck-thread-1] ERROR [o.a.d.r.exchange.support.header.ReconnectTimerTask] ReconnectTimerTask.java:51 -  [DUBBO] Fail to connect to HeaderExchangeClient [channel=org.apache.dubbo.remoting.transport.netty4.NettyClient [172.30.3.159:0 -&gt; /172.30.2.17:20880]], dubbo version: 2.7.3, current host: 172.30.3.159
org.apache.dubbo.remoting.RemotingException: client(url: dubbo://172.30.2.17:20880/com.alibaba.cloud.dubbo.service.DubboMetadataService?anyhost=true&amp;application=com-petkit-message-service&amp;bind.ip=172.30.2.17&amp;bind.port=20880&amp;check=false&amp;codec=dubbo&amp;deprecated=false&amp;dubbo=2.0.2&amp;dynamic=true&amp;generic=true&amp;group=com-petkit-sms-service&amp;heartbeat=60000&amp;interface=com.alibaba.cloud.dubbo.service.DubboMetadataService&amp;lazy=false&amp;methods=getAllServiceKeys,getServiceRestMetadata,getExportedURLs,getAllExportedURLs&amp;pid=6&amp;qos.enable=false&amp;register=true&amp;register.ip=172.30.3.159&amp;release=2.7.3&amp;remote.application=com-petkit-sms-service&amp;revision=2.1.1.RELEASE&amp;side=consumer&amp;sticky=false&amp;timestamp=1594901114548&amp;version=1.0.0) failed to connect to server /172.30.2.17:20880 client-side timeout 3000ms (elapsed: 3002ms) from netty client 172.30.3.159 using dubbo version 2.7.3
        at org.apache.dubbo.remoting.transport.netty4.NettyClient.doConnect(NettyClient.java:171)
        at org.apache.dubbo.remoting.transport.AbstractClient.connect(AbstractClient.java:190)
        at org.apache.dubbo.remoting.transport.AbstractClient.reconnect(AbstractClient.java:246)
        at org.apache.dubbo.remoting.exchange.support.header.HeaderExchangeClient.reconnect(HeaderExchangeClient.java:155)
        at org.apache.dubbo.remoting.exchange.support.header.ReconnectTimerTask.doTask(ReconnectTimerTask.java:49)
        at org.apache.dubbo.remoting.exchange.support.header.AbstractTimerTask.run(AbstractTimerTask.java:87)
        at org.apache.dubbo.common.timer.HashedWheelTimer$HashedWheelTimeout.expire(HashedWheelTimer.java:648)
        at org.apache.dubbo.common.timer.HashedWheelTimer$HashedWheelBucket.expireTimeouts(HashedWheelTimer.java:727)
        at org.apache.dubbo.common.timer.HashedWheelTimer$Worker.run(HashedWheelTimer.java:449)
        at java.lang.Thread.run(Thread.java:748)"><pre class="notranslate"><code class="notranslate">2020-07-17 14:48:09,908 [com.alibaba.nacos.naming.client.listener] ERROR [c.a.c.d.s.DubboMetadataServi
ceInvocationHandler] DubboMetadataServiceInvocationHandler.java:59 - [failed 5 times] Failed to invoke
 the method getExportedURLs in the service org.apache.dubbo.rpc.service.GenericService. Tried 3 times 
of the providers [172.30.2.17:20880] (1/1) from the registry localhost:9090 on the consumer 172.30.3.1
59 using the dubbo version 2.7.3. Last error is: Failed to invoke remote method: $invoke, provider: du
bbo://172.30.2.17:20880/com.alibaba.cloud.dubbo.service.DubboMetadataService?anyhost=true&amp;application=
com-petkit-message-service&amp;bind.ip=172.30.2.17&amp;bind.port=20880&amp;check=false&amp;deprecated=false&amp;dubbo=2.0.
2&amp;dynamic=true&amp;generic=true&amp;group=com-petkit-sms-service&amp;interface=com.alibaba.cloud.dubbo.service.Dub
boMetadataService&amp;lazy=false&amp;methods=getAllServiceKeys,getServiceRestMetadata,getExportedURLs,getAllEx
portedURLs&amp;pid=6&amp;qos.enable=false&amp;register=true&amp;register.ip=172.30.3.159&amp;release=2.7.3&amp;remote.applicat
ion=com-petkit-sms-service&amp;revision=2.1.1.RELEASE&amp;side=consumer&amp;sticky=false&amp;timestamp=1594901114548&amp;v
ersion=1.0.0, cause: message can not send, because channel is closed . url:dubbo://172.30.2.17:20880/c
om.alibaba.cloud.dubbo.service.DubboMetadataService?anyhost=true&amp;application=com-petkit-message-servic
e&amp;bind.ip=172.30.2.17&amp;bind.port=20880&amp;check=false&amp;codec=dubbo&amp;deprecated=false&amp;dubbo=2.0.2&amp;dynamic=tru
e&amp;generic=true&amp;group=com-petkit-sms-service&amp;heartbeat=60000&amp;interface=com.alibaba.cloud.dubbo.service.
DubboMetadataService&amp;lazy=false&amp;methods=getAllServiceKeys,getServiceRestMetadata,getExportedURLs,getAl
lExportedURLs&amp;pid=6&amp;qos.enable=false&amp;register=true&amp;register.ip=172.30.3.159&amp;release=2.7.3&amp;remote.appli
cation=com-petkit-sms-service&amp;revision=2.1.1.RELEASE&amp;side=consumer&amp;sticky=false&amp;timestamp=159490111454
8&amp;version=1.0.0
org.apache.dubbo.rpc.RpcException: Failed to invoke the method getExportedURLs in the service org.apac
he.dubbo.rpc.service.GenericService. Tried 3 times of the providers [172.30.2.17:20880] (1/1) from the
 registry localhost:9090 on the consumer 172.30.3.159 using the dubbo version 2.7.3. Last error is: Fa
iled to invoke remote method: $invoke, provider: dubbo://172.30.2.17:20880/com.alibaba.cloud.dubbo.ser
vice.DubboMetadataService?anyhost=true&amp;application=com-petkit-message-service&amp;bind.ip=172.30.2.17&amp;bind
.port=20880&amp;check=false&amp;deprecated=false&amp;dubbo=2.0.2&amp;dynamic=true&amp;generic=true&amp;group=com-petkit-sms-se
rvice&amp;interface=com.alibaba.cloud.dubbo.service.DubboMetadataService&amp;lazy=false&amp;methods=getAllServiceK
eys,getServiceRestMetadata,getExportedURLs,getAllExportedURLs&amp;pid=6&amp;qos.enable=false&amp;register=true&amp;reg
ister.ip=172.30.3.159&amp;release=2.7.3&amp;remote.application=com-petkit-sms-service&amp;revision=2.1.1.RELEASE&amp;s
ide=consumer&amp;sticky=false&amp;timestamp=1594901114548&amp;version=1.0.0, cause: message can not send, because 
channel is closed . url:dubbo://172.30.2.17:20880/com.alibaba.cloud.dubbo.service.DubboMetadataService
?anyhost=true&amp;application=com-petkit-message-service&amp;bind.ip=172.30.2.17&amp;bind.port=20880&amp;check=false&amp;c
odec=dubbo&amp;deprecated=false&amp;dubbo=2.0.2&amp;dynamic=true&amp;generic=true&amp;group=com-petkit-sms-service&amp;heartbe
at=60000&amp;interface=com.alibaba.cloud.dubbo.service.DubboMetadataService&amp;lazy=false&amp;methods=getAllServi
ceKeys,getServiceRestMetadata,getExportedURLs,getAllExportedURLs&amp;pid=6&amp;qos.enable=false&amp;register=true&amp;
register.ip=172.30.3.159&amp;release=2.7.3&amp;remote.application=com-petkit-sms-service&amp;revision=2.1.1.RELEAS
E&amp;side=consumer&amp;sticky=false&amp;timestamp=1594901114548&amp;version=1.0.0
        at org.apache.dubbo.rpc.cluster.support.FailoverClusterInvoker.doInvoke(FailoverClusterInvoker.java:113)
        at org.apache.dubbo.rpc.cluster.support.AbstractClusterInvoker.invoke(AbstractClusterInvoker.java:248)
        at org.apache.dubbo.rpc.cluster.support.wrapper.MockClusterInvoker.invoke(MockClusterInvoker.java:78)
        at org.apache.dubbo.rpc.proxy.InvokerInvocationHandler.invoke(InvokerInvocationHandler.java:55)
        at org.apache.dubbo.common.bytecode.proxy6.$invoke(proxy6.java)
        at com.alibaba.cloud.dubbo.service.DubboMetadataServiceInvocationHandler.invoke(DubboMetadataServiceInvocationHandler.java:54)
        at com.sun.proxy.$Proxy138.getExportedURLs(Unknown Source)
        at com.alibaba.cloud.dubbo.registry.AbstractSpringCloudRegistry.getExportedURLs(AbstractSpringCloudRegistry.java:338)
        at com.alibaba.cloud.dubbo.registry.AbstractSpringCloudRegistry.subscribeDubboServiceURL(AbstractSpringCloudRegistry.java:272)
        at com.alibaba.cloud.dubbo.registry.AbstractSpringCloudRegistry$1.onApplicationEvent(AbstractSpringCloudRegistry.java:195)
        at com.alibaba.cloud.dubbo.registry.AbstractSpringCloudRegistry$1.onApplicationEvent(AbstractSpringCloudRegistry.java:188)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
        at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:402)
        at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:359)
        at com.alibaba.cloud.dubbo.autoconfigure.DubboServiceDiscoveryAutoConfiguration.dispatchServiceInstancesChangedEvent(DubboServiceDiscoveryAutoConfiguration.java:168)
        at com.alibaba.cloud.dubbo.autoconfigure.DubboServiceDiscoveryAutoConfiguration.access$200(DubboServiceDiscoveryAutoConfiguration.java:105)
        at com.alibaba.cloud.dubbo.autoconfigure.DubboServiceDiscoveryAutoConfiguration$NacosConfiguration.lambda$subscribeEventListener$1(DubboServiceDiscoveryAutoConfiguration.java:551)
        at com.alibaba.nacos.client.naming.core.EventDispatcher$Notifier.run(EventDispatcher.java:128)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
Caused by: org.apache.dubbo.remoting.RemotingException: message can not send, because channel is closed . url:dubbo://172.30.2.17:20880/com.alibaba.cloud.dubbo.service.DubboMetadataService?anyhost=true&amp;application=com-petkit-message-service&amp;bind.ip=172.30.2.17&amp;bind.port=20880&amp;check=false&amp;codec=dubbo&amp;deprecated=false&amp;dubbo=2.0.2&amp;dynamic=true&amp;generic=true&amp;group=com-petkit-sms-service&amp;heartbeat=60000&amp;interface=com.alibaba.cloud.dubbo.service.DubboMetadataService&amp;lazy=false&amp;methods=getAllServiceKeys,getServiceRestMetadata,getExportedURLs,getAllExportedURLs&amp;pid=6&amp;qos.enable=false&amp;register=true&amp;register.ip=172.30.3.159&amp;release=2.7.3&amp;remote.application=com-petkit-sms-service&amp;revision=2.1.1.RELEASE&amp;side=consumer&amp;sticky=false&amp;timestamp=1594901114548&amp;version=1.0.0
        at org.apache.dubbo.remoting.transport.AbstractClient.send(AbstractClient.java:175)
        at org.apache.dubbo.remoting.transport.AbstractPeer.send(AbstractPeer.java:53)
        at org.apache.dubbo.remoting.exchange.support.header.HeaderExchangeChannel.request(HeaderExchangeChannel.java:118)
        at org.apache.dubbo.remoting.exchange.support.header.HeaderExchangeClient.request(HeaderExchangeClient.java:84)
        at org.apache.dubbo.rpc.protocol.dubbo.ReferenceCountExchangeClient.request(ReferenceCountExchangeClient.java:80)
        at org.apache.dubbo.rpc.protocol.dubbo.DubboInvoker.doInvoke(DubboInvoker.java:97)
        at org.apache.dubbo.rpc.protocol.AbstractInvoker.invoke(AbstractInvoker.java:155)
        at org.apache.dubbo.rpc.protocol.AsyncToSyncInvoker.invoke(AsyncToSyncInvoker.java:52)
        at org.apache.dubbo.rpc.listener.ListenerInvokerWrapper.invoke(ListenerInvokerWrapper.java:78)
        at org.apache.dubbo.rpc.filter.GenericImplFilter.invoke(GenericImplFilter.java:119)
        at org.apache.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:82)
        at org.apache.dubbo.monitor.support.MonitorFilter.invoke(MonitorFilter.java:92)
        at org.apache.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:82)
        at org.apache.dubbo.rpc.protocol.dubbo.filter.FutureFilter.invoke(FutureFilter.java:54)
        at org.apache.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:82)
        at org.apache.dubbo.rpc.filter.ConsumerContextFilter.invoke(ConsumerContextFilter.java:58)
        at org.apache.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:82)
        at org.apache.dubbo.rpc.protocol.ProtocolFilterWrapper$CallbackRegistrationInvoker.invoke(ProtocolFilterWrapper.java:157)
        at org.apache.dubbo.rpc.protocol.InvokerWrapper.invoke(InvokerWrapper.java:56)
        at org.apache.dubbo.rpc.cluster.support.FailoverClusterInvoker.doInvoke(FailoverClusterInvoker.java:82)
        ... 22 common frames omitted
2020-07-17 14:48:42,077 [dubbo-client-idleCheck-thread-1] INFO  [o.a.d.r.exchange.support.header.ReconnectTimerTask] ReconnectTimerTask.java:48 -  [DUBBO] Initial connection to HeaderExchangeClient [channel=org.apache.dubbo.remoting.transport.netty4.NettyClient [172.30.3.159:0 -&gt; /172.30.2.17:20880]], dubbo version: 2.7.3, current host: 172.30.3.159
2020-07-17 14:48:45,084 [dubbo-client-idleCheck-thread-1] ERROR [o.a.d.r.exchange.support.header.ReconnectTimerTask] ReconnectTimerTask.java:51 -  [DUBBO] Fail to connect to HeaderExchangeClient [channel=org.apache.dubbo.remoting.transport.netty4.NettyClient [172.30.3.159:0 -&gt; /172.30.2.17:20880]], dubbo version: 2.7.3, current host: 172.30.3.159
org.apache.dubbo.remoting.RemotingException: client(url: dubbo://172.30.2.17:20880/com.alibaba.cloud.dubbo.service.DubboMetadataService?anyhost=true&amp;application=com-petkit-message-service&amp;bind.ip=172.30.2.17&amp;bind.port=20880&amp;check=false&amp;codec=dubbo&amp;deprecated=false&amp;dubbo=2.0.2&amp;dynamic=true&amp;generic=true&amp;group=com-petkit-sms-service&amp;heartbeat=60000&amp;interface=com.alibaba.cloud.dubbo.service.DubboMetadataService&amp;lazy=false&amp;methods=getAllServiceKeys,getServiceRestMetadata,getExportedURLs,getAllExportedURLs&amp;pid=6&amp;qos.enable=false&amp;register=true&amp;register.ip=172.30.3.159&amp;release=2.7.3&amp;remote.application=com-petkit-sms-service&amp;revision=2.1.1.RELEASE&amp;side=consumer&amp;sticky=false&amp;timestamp=1594901114548&amp;version=1.0.0) failed to connect to server /172.30.2.17:20880 client-side timeout 3000ms (elapsed: 3002ms) from netty client 172.30.3.159 using dubbo version 2.7.3
        at org.apache.dubbo.remoting.transport.netty4.NettyClient.doConnect(NettyClient.java:171)
        at org.apache.dubbo.remoting.transport.AbstractClient.connect(AbstractClient.java:190)
        at org.apache.dubbo.remoting.transport.AbstractClient.reconnect(AbstractClient.java:246)
        at org.apache.dubbo.remoting.exchange.support.header.HeaderExchangeClient.reconnect(HeaderExchangeClient.java:155)
        at org.apache.dubbo.remoting.exchange.support.header.ReconnectTimerTask.doTask(ReconnectTimerTask.java:49)
        at org.apache.dubbo.remoting.exchange.support.header.AbstractTimerTask.run(AbstractTimerTask.java:87)
        at org.apache.dubbo.common.timer.HashedWheelTimer$HashedWheelTimeout.expire(HashedWheelTimer.java:648)
        at org.apache.dubbo.common.timer.HashedWheelTimer$HashedWheelBucket.expireTimeouts(HashedWheelTimer.java:727)
        at org.apache.dubbo.common.timer.HashedWheelTimer$Worker.run(HashedWheelTimer.java:449)
        at java.lang.Thread.run(Thread.java:748)
</code></pre></div>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> I have searched the <a href="https://github.com/apache/dubbo/issues">issues</a> of this repository and believe that this is not a duplicate.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> I have checked the <a href="https://github.com/apache/dubbo/blob/master/FAQ.md">FAQ</a> of this repository and believe that this is not a duplicate.</li>
</ul>
<h3 dir="auto">Environment</h3>
<ul dir="auto">
<li>Dubbo version: 2.7.6</li>
<li>Operating System version: windows、ubuntu</li>
<li>Java version: 11</li>
<li>Spring Boot version：2.2.6.RELEASE</li>
<li>Spring Cloud version：Hoxton.RELEASE</li>
<li>Spring Cloud Alibaba version：2.2.1.RELEASE</li>
</ul>
<h3 dir="auto">Steps to reproduce this issue</h3>
<ol dir="auto">
<li>
<p dir="auto">如果现在有2个consumer，2个provider，如图：<br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/7941760/93584757-54d94a00-f9d8-11ea-9b2b-0171c4259998.png"><img src="https://user-images.githubusercontent.com/7941760/93584757-54d94a00-f9d8-11ea-9b2b-0171c4259998.png" alt="image" style="max-width: 100%;"></a></p>
</li>
<li>
<p dir="auto">现打算对部分接口进行不兼容升级：<br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/7941760/93584947-a5e93e00-f9d8-11ea-932a-c0c244ab9a27.png"><img src="https://user-images.githubusercontent.com/7941760/93584947-a5e93e00-f9d8-11ea-932a-c0c244ab9a27.png" alt="image" style="max-width: 100%;"></a></p>
</li>
</ol>
<p dir="auto">3.升级之后，根据版本号匹配的原则，consumer1应该只会refer到provider1，原来的consumer2只会refer到provider2。</p>
<p dir="auto">Pls. provide [GitHub address] to reproduce this issue.</p>
<h3 dir="auto">Expected Result</h3>
<p dir="auto">What do you expected from the above steps？<br>
consumer1应该只会refer到provider1，原来的consumer2只会refer到provider2。</p>
<h3 dir="auto">Actual Result</h3>
<p dir="auto">What actually happens?</p>
<p dir="auto">从源码来看，服务引入的过程似乎和版本没有关系。<br>
1、在AbstractSpringCloudRegistry.subscribeDubboServiceURL方法中，有这样一段：</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="List&lt;URL&gt; exportedURLs = getExportedURLs(dubboMetadataService, url);
		for (URL exportedURL : exportedURLs) {
			String protocol = exportedURL.getProtocol();
			List&lt;URL&gt; subscribedURLs = new LinkedList&lt;&gt;();
			serviceInstances.forEach(serviceInstance -&gt; {
				Integer port = repository.getDubboProtocolPort(serviceInstance, protocol);
				String host = serviceInstance.getHost();
				if (port == null) {
					if (logger.isWarnEnabled()) {
						logger.warn(
								&quot;The protocol[{}] port of Dubbo  service instance[host : {}] &quot;
										+ &quot;can't be resolved&quot;,
								protocol, host);
					}
				}
				else {
					URL subscribedURL = new URL(protocol, host, port,
							exportedURL.getParameters());
					subscribedURLs.add(subscribedURL);
				}
			});

			allSubscribedURLs.addAll(subscribedURLs);
		}"><pre class="notranslate"><code class="notranslate">List&lt;URL&gt; exportedURLs = getExportedURLs(dubboMetadataService, url);
		for (URL exportedURL : exportedURLs) {
			String protocol = exportedURL.getProtocol();
			List&lt;URL&gt; subscribedURLs = new LinkedList&lt;&gt;();
			serviceInstances.forEach(serviceInstance -&gt; {
				Integer port = repository.getDubboProtocolPort(serviceInstance, protocol);
				String host = serviceInstance.getHost();
				if (port == null) {
					if (logger.isWarnEnabled()) {
						logger.warn(
								"The protocol[{}] port of Dubbo  service instance[host : {}] "
										+ "can't be resolved",
								protocol, host);
					}
				}
				else {
					URL subscribedURL = new URL(protocol, host, port,
							exportedURL.getParameters());
					subscribedURLs.add(subscribedURL);
				}
			});

			allSubscribedURLs.addAll(subscribedURLs);
		}
</code></pre></div>
<p dir="auto">可以看出，该段代码从dubboMetadataService获取exportedURLs，然后遍历所有的provider serviceInstance，生成最终的allSubscribedURLs。<br>
然后跟踪dubboMetadataService的代码，在DubboServiceMetadataRepository.initSubscribedDubboMetadataService中有这样一段：</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Optional&lt;ServiceInstance&gt; optionalServiceInstance = metadataServiceInstanceSelector
				.choose(discoveryClient.getInstances(serviceName));
		if (!((Optional) optionalServiceInstance).isPresent()) {
			return false;
		}
		ServiceInstance serviceInstance = optionalServiceInstance.get();
		if (null == serviceInstance) {
			return false;
		}"><pre class="notranslate"><code class="notranslate">Optional&lt;ServiceInstance&gt; optionalServiceInstance = metadataServiceInstanceSelector
				.choose(discoveryClient.getInstances(serviceName));
		if (!((Optional) optionalServiceInstance).isPresent()) {
			return false;
		}
		ServiceInstance serviceInstance = optionalServiceInstance.get();
		if (null == serviceInstance) {
			return false;
		}
</code></pre></div>
<p dir="auto">这里仅仅是从discoveryClient.getInstances(serviceName)返回的provider实例中随机选取了一个（stream.findAny()）实例，然后用来作为获取dubboMetadataServiceURL的实例。这样看的话，consumer要根据版本号调用匹配版本号的provider似乎并不能实现，而在实际使用中也发现，在以下场景下：<br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/7941760/93586439-e5b12500-f9da-11ea-8822-0c2ac4d21941.png"><img src="https://user-images.githubusercontent.com/7941760/93586439-e5b12500-f9da-11ea-8822-0c2ac4d21941.png" alt="image" style="max-width: 100%;"></a><br>
如果consumer1在服务引用时，选择的dubboMetadataService是provider1时，最终consumer1引用的invokers会包含provider1和provider2，导致调用会有50%的几率成功。<br>
如果consumer1在服务引用时，选择的dubboMetadataService是provider2时，最终consumer1引用的invokers是空的，导致调用会100%失败。</p>