Policy datastore has a potential connection leak in one error case. If findPolicyWithSameName returns an error then the transaction could be stuck forever.
ctx, tx, err := ds.storage.Begin(ctx) if err != nil { return "", err } policyNameToPolicyMap := make(map[string]*storage.Policy, len(allPolicies)) for _, policy := range allPolicies { policyNameToPolicyMap[policy.GetName()] = policy } if findPolicyWithSameName(policyNameToPolicyMap, policy.GetName()) != nil { return "", fmt.Errorf("Could not add policy due to name validation, policy with name %s already exists", policy.GetName()) } policyutils.FillSortHelperFields(policy) // Any policy added after startup must be marked custom policy. markPoliciesAsCustom(policy) // Stash away the category names, since they need to be erased on storage. But the policy insert must happen first, // to get an ID, to satisfy foreign key constraints when policy category edges are added. policyCategories := policy.GetCategories()