wuwen5 commented on pull request #8907:
URL: https://github.com/apache/dubbo/pull/8907#issuecomment-958703542
NacosRegistry 存在一个严重的内存泄露问题,在dubbo
admin中出现,经过分析发现被这个pr解决了,建议2.7.x尽早发布一个release版本.
```
private void subscribeEventListener(String serviceName, final URL url, final
NotifyListener listener)
throws NacosException {
EventListener eventListener = event -> {
if (event instanceof NamingEvent) {
NamingEvent e = (NamingEvent) event;
List<Instance> instances = e.getInstances();
if (isServiceNamesWithCompatibleMode(url)) {
/**
* Get all instances with corresponding serviceNames to
avoid instance overwrite and but with empty instance mentioned
* in https://github.com/apache/dubbo/issues/5885 and
https://github.com/apache/dubbo/issues/5899
*/
NacosInstanceManageUtil.initOrRefreshServiceInstanceList(serviceName,
instances);
instances =
NacosInstanceManageUtil.getAllCorrespondingServiceInstanceList(serviceName);
}
notifySubscriber(url, listener, instances);
}
};
namingService.subscribe(serviceName,
getUrl().getParameter(GROUP_KEY, Constants.DEFAULT_GROUP),
eventListener);
}
```
```EventListener eventListener```实例会无限制存储到 nacos
```InstancesChangeNotifier#listenerMap```的ConcurrentHashSet中
```
public class InstancesChangeNotifier extends
Subscriber<InstancesChangeEvent> {
private final Map<String, ConcurrentHashSet<EventListener>> listenerMap
= new ConcurrentHashMap<String, ConcurrentHashSet<EventListener>>();
private final Object lock = new Object();
/**
* register listener.
*
* @param serviceName combineServiceName, such as 'xxx@@xxx'
* @param clusters clusters, concat by ','. such as 'xxx,yyy'
* @param listener custom listener
*/
public void registerListener(String serviceName, String clusters,
EventListener listener) {
String key = ServiceInfo.getKey(serviceName, clusters);
ConcurrentHashSet<EventListener> eventListeners =
listenerMap.get(key);
if (eventListeners == null) {
synchronized (lock) {
eventListeners = listenerMap.get(key);
if (eventListeners == null) {
eventListeners = new ConcurrentHashSet<EventListener>();
listenerMap.put(key, eventListeners);
}
}
}
eventListeners.add(listener);
}
...
}
```


--
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]