From 9c67965d6c3262afd8e85b9219f141ffde5f9c6f Mon Sep 17 00:00:00 2001 From: congqixia Date: Thu, 22 Aug 2024 16:30:57 +0800 Subject: [PATCH] fix: [2.4] Re-read value after `once` initialization (#35643) Cherry-pick from master pr: #35642 Related to #35641 See also #35271 Signed-off-by: Congqi Xia --- internal/proxy/privilege_cache.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/internal/proxy/privilege_cache.go b/internal/proxy/privilege_cache.go index f319b705dc27f..611dd0fb5b4e9 100644 --- a/internal/proxy/privilege_cache.go +++ b/internal/proxy/privilege_cache.go @@ -41,12 +41,14 @@ func getPriCache() *PrivilegeCache { priCacheInitOnce.Do(func() { priCacheMut.Lock() defer priCacheMut.Unlock() - c = &PrivilegeCache{ + priCache = &PrivilegeCache{ version: ver.Inc(), values: typeutil.ConcurrentMap[string, bool]{}, } - priCache = c }) + priCacheMut.RLock() + defer priCacheMut.RUnlock() + c = priCache } return c