From 8d453e62a8c45c2944dc2f08b34f9423d8b5ccd1 Mon Sep 17 00:00:00 2001 From: nkorange Date: Tue, 23 Jul 2019 16:36:55 +0800 Subject: [PATCH] Fix #1591 --- .../ephemeral/distro/DistroConsistencyServiceImpl.java | 5 +++++ .../java/com/alibaba/nacos/naming/core/ServiceManager.java | 3 +++ 2 files changed, 8 insertions(+) diff --git a/naming/src/main/java/com/alibaba/nacos/naming/consistency/ephemeral/distro/DistroConsistencyServiceImpl.java b/naming/src/main/java/com/alibaba/nacos/naming/consistency/ephemeral/distro/DistroConsistencyServiceImpl.java index 65448e8a0..145ee6b5e 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/consistency/ephemeral/distro/DistroConsistencyServiceImpl.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/consistency/ephemeral/distro/DistroConsistencyServiceImpl.java @@ -322,6 +322,11 @@ public class DistroConsistencyServiceImpl implements EphemeralConsistencyService if (!listeners.containsKey(key)) { listeners.put(key, new CopyOnWriteArrayList<>()); } + + if (listeners.get(key).contains(listener)) { + return; + } + listeners.get(key).add(listener); } diff --git a/naming/src/main/java/com/alibaba/nacos/naming/core/ServiceManager.java b/naming/src/main/java/com/alibaba/nacos/naming/core/ServiceManager.java index e45ec2b12..7daaf5a27 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/core/ServiceManager.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/core/ServiceManager.java @@ -143,6 +143,9 @@ public class ServiceManager implements RecordListener { if (oldDom != null) { oldDom.update(service); + // re-listen to handle the situation when the underlying listener is removed: + consistencyService.listen(KeyBuilder.buildInstanceListKey(service.getNamespaceId(), service.getName(), true), oldDom); + consistencyService.listen(KeyBuilder.buildInstanceListKey(service.getNamespaceId(), service.getName(), false), oldDom); } else { putService(service); service.init();