From b487b176fda1af68dfe333b7b999721b580a34f3 Mon Sep 17 00:00:00 2001 From: Shriram Sharma Date: Mon, 23 May 2022 15:03:26 -0700 Subject: [PATCH] used defer to release the mutex --- admiral/pkg/controller/common/types.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/admiral/pkg/controller/common/types.go b/admiral/pkg/controller/common/types.go index a05418df..91e20a26 100644 --- a/admiral/pkg/controller/common/types.go +++ b/admiral/pkg/controller/common/types.go @@ -177,10 +177,9 @@ func (s *SidecarEgressMap) Put(identity string, namespace string, fqdn string, c } func (s *SidecarEgressMap) Get(key string) map[string]SidecarEgress { + defer s.mutex.Unlock() s.mutex.Lock() - val := s.cache[key] - s.mutex.Unlock() - return val + return s.cache[key] } func (s *SidecarEgressMap) Delete(key string) { @@ -198,9 +197,9 @@ func (s *SidecarEgressMap) Map() map[string]map[string]SidecarEgress { // Range is a thread safe iterator to iterate through the SidecarEgress map func (s *SidecarEgressMap) Range(fn func(k string, v map[string]SidecarEgress)) { + defer s.mutex.Unlock() s.mutex.Lock() for k, v := range s.cache { fn(k, v) } - s.mutex.Unlock() }