Skip to content

Commit

Permalink
fix: initialize transactionMu in NewAdapterByDBUseTableName
Browse files Browse the repository at this point in the history
constructor NewAdapterByDBUseTableName should initialize transactionMu,
otherwise it will ~~panic~~ blocked due to that cas when calling Transaction

Besides, a few other constructors also depend on NewAdapterByDBUseTableName,
if transactionMu is not initialized in NewAdapterByDBUseTableName,
it will blocked as well.
  • Loading branch information
yuikns committed May 30, 2024
1 parent 15ac848 commit be365f5
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,9 @@ func NewAdapterByDBUseTableName(db *gorm.DB, prefix string, tableName string) (*
}

a := &Adapter{
tablePrefix: prefix,
tableName: tableName,
tablePrefix: prefix,
tableName: tableName,
transactionMu: &sync.Mutex{},
}

a.db = db.Scopes(a.casbinRuleTable()).Session(&gorm.Session{Context: db.Statement.Context})
Expand Down

0 comments on commit be365f5

Please sign in to comment.