Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
fix(store): remove nested transaction patterns to prevent deadlock (#18906)
p0nya51c34b919a2
diff --git a/backend/store/group.go b/backend/store/group.goindex a964b9fb12..7ca1646a96 100644--- a/backend/store/group.go+++ b/backend/store/group.go@@ -57,19 +57,10 @@ func (s *Store) GetGroup(ctx context.Context, find *FindGroupMessage) (*GroupMes}}- tx, err := s.GetDB().BeginTx(ctx, nil)- if err != nil {- return nil, err- }- defer tx.Rollback()-groups, err := s.ListGroups(ctx, find)if err != nil {return nil, err}- if err := tx.Commit(); err != nil {- return nil, err- }if len(groups) == 0 {return nil, nildiff --git a/backend/store/idp.go b/backend/store/idp.goindex cc1000730f..2e1718b251 100644--- a/backend/store/idp.go+++ b/backend/store/idp.go@@ -98,19 +98,10 @@ func (s *Store) CreateIdentityProvider(ctx context.Context, create *IdentityProv// GetIdentityProvider gets an identity provider.func (s *Store) GetIdentityProvider(ctx context.Context, find *FindIdentityProviderMessage) (*IdentityProviderMessage, error) {- tx, err := s.GetDB().BeginTx(ctx, &sql.TxOptions{ReadOnly: true})- if err != nil {- return nil, err- }- defer tx.Rollback()-identityProviders, err := s.ListIdentityProviders(ctx, find)if err != nil {return nil, err}- if err := tx.Commit(); err != nil {- return nil, err- }if len(identityProviders) == 0 {return nil, nildiff --git a/backend/store/instance.go b/backend/store/instance.goindex 3c0cc06fcd..26876e3365 100644--- a/backend/store/instance.go+++ b/backend/store/instance.go@@ -173,12 +173,6 @@ func (s *Store) CreateInstance(ctx context.Context, instanceCreate *InstanceMessreturn nil, err}- tx, err := s.GetDB().BeginTx(ctx, nil)- if err != nil {- return nil, err- }- defer tx.Rollback()-redacted, err := s.obfuscateInstance(ctx, instanceCreate.Metadata)if err != nil {return nil, err@@ -191,6 +185,13 @@ func (s *Store) CreateInstance(ctx context.Context, instanceCreate *InstanceMessif instanceCreate.EnvironmentID != nil && *instanceCreate.EnvironmentID != "" {environment = instanceCreate.EnvironmentID}++ tx, err := s.GetDB().BeginTx(ctx, nil)+ if err != nil {+ return nil, err+ }+ defer tx.Rollback()+q := qb.Q().Space(`INSERT INTO instance (resource_id,diff --git a/backend/store/policy.go b/backend/store/policy.goindex 4d4be075bc..0961612d5c 100644--- a/backend/store/policy.go+++ b/backend/store/policy.go@@ -453,12 +453,6 @@ func (s *Store) GetPolicy(ctx context.Context, find *FindPolicyMessage) (*Policy}}- tx, err := s.GetDB().BeginTx(ctx, nil)- if err != nil {- return nil, err- }- defer tx.Rollback()-// We will always return the resource regardless of its deleted state.find.ShowAll = truepolicies, err := s.ListPolicies(ctx, find)@@ -477,10 +471,6 @@ func (s *Store) GetPolicy(ctx context.Context, find *FindPolicyMessage) (*Policy}policy := policies[0]- if err := tx.Commit(); err != nil {- return nil, err- }-s.policyCache.Add(getPolicyCacheKey(policy.ResourceType, policy.Resource, policy.Type), policy)return policy, nil