From cea21e995a0d4ea7fda4745c4de0406d40976115 Mon Sep 17 00:00:00 2001 From: liaochuntao Date: Tue, 16 Apr 2024 14:39:26 +0800 Subject: [PATCH] refactor:fix config notify watch client may cause client hangup (#1348) --- config/watcher.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/config/watcher.go b/config/watcher.go index 1af7ff556..7934fc5c4 100644 --- a/config/watcher.go +++ b/config/watcher.go @@ -302,6 +302,7 @@ func (wc *watchCenter) RemoveAllWatcher(clientId string) { } watchers.Remove(clientId) } + wc.clients.Delete(clientId) } // RemoveWatcher 删除订阅者 @@ -345,11 +346,10 @@ func (wc *watchCenter) notifyToWatchers(publishConfigFile *model.SimpleConfigFil if watchCtx.ShouldNotify(publishConfigFile) { watchCtx.Reply(response) notifyCnt++ - } - // 只能用一次,通知完就要立马清理掉这个 WatchContext - if watchCtx.IsOnce() { - wc.clients.Delete(clientId) - wc.RemoveAllWatcher(watchCtx.ClientID()) + // 只能用一次,通知完就要立马清理掉这个 WatchContext + if watchCtx.IsOnce() { + wc.RemoveAllWatcher(watchCtx.ClientID()) + } } })