From 60a2a3aa9decac80512142111f6cfb8bf68a186a Mon Sep 17 00:00:00 2001 From: Qiu Jian Date: Tue, 30 Aug 2022 07:31:00 +0800 Subject: [PATCH] fix: policy cache get/set with atomic ops --- pkg/cloudcommon/policy/policy.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/cloudcommon/policy/policy.go b/pkg/cloudcommon/policy/policy.go index 9071b2f922..782a5e1a2f 100644 --- a/pkg/cloudcommon/policy/policy.go +++ b/pkg/cloudcommon/policy/policy.go @@ -239,14 +239,14 @@ type policyTask struct { } func (t *policyTask) Run() { - val := t.manager.policyCache.Get(t.key) + val := t.manager.policyCache.AtomicGet(t.key) result := fetchResult{} if gotypes.IsNil(val) { pg, err := DefaultPolicyFetcher(context.Background(), t.userCred) if err != nil { result.err = errors.Wrap(err, "DefaultPolicyFetcher") } else { - t.manager.policyCache.Set(t.key, pg) + t.manager.policyCache.AtomicSet(t.key, pg) result.output = pg } } else { @@ -297,7 +297,7 @@ func (manager *SPolicyManager) allow(scope rbacutils.TRbacScope, userCred mcclie policySet = rbacutils.TPolicySet{} } result := manager.allowWithoutCache(policySet, scope, userCred, service, resource, action, extra...) - manager.permissionCache.Set(key, result) + manager.permissionCache.AtomicSet(key, result) return result }