From 430a22be67ac798718aa6cabcc79d05bc24bd143 Mon Sep 17 00:00:00 2001 From: songzhibin97 <718428482@qq.com> Date: Thu, 20 May 2021 10:49:00 +0800 Subject: [PATCH] fix casbin datarace --- server/service/sys_casbin.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/server/service/sys_casbin.go b/server/service/sys_casbin.go index 6e72c5ff..556dd086 100644 --- a/server/service/sys_casbin.go +++ b/server/service/sys_casbin.go @@ -91,8 +91,9 @@ func ClearCasbin(v int, p ...string) bool { //@return: *casbin.Enforcer var ( - e *casbin.Enforcer - once sync.Once + e *casbin.Enforcer + once sync.Once + eLock sync.Mutex ) func Casbin() *casbin.Enforcer { @@ -101,7 +102,9 @@ func Casbin() *casbin.Enforcer { e, _ = casbin.NewEnforcer(global.GVA_CONFIG.Casbin.ModelPath, a) e.AddFunction("ParamsMatch", ParamsMatchFunc) }) + eLock.Lock() _ = e.LoadPolicy() + eLock.Unlock() return e }