saleson opened a new issue, #9965:
URL: https://github.com/apache/dubbo/issues/9965
### Environment
* Dubbo version: 3.0.7
* Java version: 1.8
### Steps to reproduce this issue
1、启动provider
2、启动consumer
3、调用一次RPC
4、停止provider
5、等60秒左右
Pls. provide [GitHub address] to reproduce this issue.
原因:
ServiceDiscoveryRegistryDirectory.refreshInvoker()和RegistryDirectory.refreshInvoker()方法中的代码逻辑顺序反了
`java
this.urlInvokerMap = newUrlInvokerMap; // urlnvokerMap =
newUrlInvokerMap = empty
try {
//call destroyAllInvokers()
destroyUnusedInvokers(oldUrlInvokerMap, newUrlInvokerMap);
// Close the unused Invoker
} catch (Exception e) {
logger.warn("destroyUnusedInvokers error. ", e);
}
`
而destroyAllInvokers()方法中是重新判断urlInvokerMap是否为空,再从urlInvokerMap中获取invoker调用其destroyAll()方法,而此时urlInvokerMap是空,所以invoker不会被destroy
`java
protected void destroyAllInvokers() {
Map<URL, Invoker<T>> localUrlInvokerMap = this.urlInvokerMap; //
local reference
if (!CollectionUtils.isEmptyMap(localUrlInvokerMap)) {
for (Invoker<T> invoker : new
ArrayList<>(localUrlInvokerMap.values())) {
try {
invoker.destroyAll();
} catch (Throwable t) {
logger.warn("Failed to destroy service " + serviceKey +
" to provider " + invoker.getUrl(), t);
}
}
localUrlInvokerMap.clear();
}
this.urlInvokerMap = null;
this.cachedInvokerUrls = null;
destroyInvokers();
}
`
### Expected Behavior
释放DubboInvoker
### Actual Behavior
没有释放 DubboInvoker及NettyClient等资源,ReconnectTimerTask会不断检查连接状态以及尝试重连然后报错(60秒间隔)
If there is an exception, please attach the exception trace:
[24/04/22 21:18:37:430 CST] dubbo-client-idleCheck-thread-1 ERROR
header.ReconnectTimerTask: [DUBBO] Fail to connect to HeaderExchangeClient
[channel=org.apache.dubbo.remoting.transport.netty4.NettyClient
[/192.168.1.7:57600 -> /192.168.1.7:20880]], dubbo version: 3.0.8-SNAPSHOT,
current host: 192.168.1.7
org.apache.dubbo.remoting.RemotingException: client(url:
dubbo://192.168.1.7:20880/org.apache.dubbo.springboot.demo.DemoService?anyhost=true&application=dubbo-springboot-demo-consumer&background=false&category=providers,configurators,routers&check=false&codec=dubbo&deprecated=false&dubbo=2.0.2&dynamic=true&generic=false&heartbeat=60000&interface=org.apache.dubbo.springboot.demo.DemoService&methods=sayHello,sayHelloAsync&pid=18417&qos.enable=false®ister-mode=interface&release=3.0.8-SNAPSHOT&side=consumer&sticky=false)
failed to connect to server /192.168.1.7:20880, error message is:Connection
refused: /192.168.1.7:20880
at
org.apache.dubbo.remoting.transport.netty4.NettyClient.doConnect(NettyClient.java:192)
at
org.apache.dubbo.remoting.transport.AbstractClient.connect(AbstractClient.java:214)
at
org.apache.dubbo.remoting.transport.AbstractClient.reconnect(AbstractClient.java:268)
at
org.apache.dubbo.remoting.exchange.support.header.HeaderExchangeClient.reconnect(HeaderExchangeClient.java:171)
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:651)
at
org.apache.dubbo.common.timer.HashedWheelTimer$HashedWheelBucket.expireTimeouts(HashedWheelTimer.java:730)
at
org.apache.dubbo.common.timer.HashedWheelTimer$Worker.run(HashedWheelTimer.java:452)
at java.lang.Thread.run(Thread.java:750)
Caused by: io.netty.channel.AbstractChannel$AnnotatedConnectException:
Connection refused: /192.168.1.7:20880
Caused by: java.net.ConnectException: Connection refused
at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
at
sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:716)
at
io.netty.channel.socket.nio.NioSocketChannel.doFinishConnect(NioSocketChannel.java:330)
at
io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:334)
at
io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:707)
at
io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:655)
at
io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:581)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493)
at
io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
at
io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
at
io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.lang.Thread.run(Thread.java:750)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]