diff --git a/pkg/corredor/service.go b/pkg/corredor/service.go index 0e4034cde..0e73696a0 100644 --- a/pkg/corredor/service.go +++ b/pkg/corredor/service.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "strings" + "sync" "time" "github.com/go-chi/chi/middleware" @@ -40,12 +41,18 @@ type ( // map[][] = true explicit map[string]map[string]bool - // Combined list of client and server scripts - sScripts ScriptSet + // List of client & server sceipts + sScripts ScriptSet + cScripts ScriptSet + + // last modified ts for c/s sScriptsTS time.Time - cScripts ScriptSet cScriptsTS time.Time + // locking for c/s loading + sScriptsL *sync.Mutex + cScriptsL *sync.Mutex + conn *grpc.ClientConn ssClient ServerScriptsClient @@ -171,6 +178,9 @@ func NewService(logger *zap.Logger, opt options.CorredorOpt) *service { permissions: permissions.RuleSet{}, userLookupCache: userLookupCacheMap{}, + + sScriptsL: &sync.Mutex{}, + cScriptsL: &sync.Mutex{}, } } @@ -400,6 +410,9 @@ func (svc *service) loadServerScripts(ctx context.Context) { rsp *ServerScriptListResponse ) + svc.sScriptsL.Lock() + defer svc.sScriptsL.Unlock() + ctx, cancel := context.WithTimeout(ctx, svc.opt.ListTimeout) defer cancel() @@ -820,6 +833,9 @@ func (svc *service) loadClientScripts(ctx context.Context) { rsp *ClientScriptListResponse ) + svc.cScriptsL.Lock() + defer svc.cScriptsL.Unlock() + ctx, cancel := context.WithTimeout(ctx, svc.opt.ListTimeout) defer cancel()