From bdb30da0a7af4329238ba2a17b46860aa4d18a65 Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Wed, 21 Oct 2020 15:47:46 +0800 Subject: [PATCH] Fix copy lock for prepared statement, close #3642, #3607 --- gorm.go | 1 + prepare_stmt.go | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/gorm.go b/gorm.go index e5c4a8a4..affa8e69 100644 --- a/gorm.go +++ b/gorm.go @@ -117,6 +117,7 @@ func Open(dialector Dialector, config *Config) (db *DB, err error) { preparedStmt := &PreparedStmtDB{ ConnPool: db.ConnPool, Stmts: map[string]*sql.Stmt{}, + Mux: &sync.RWMutex{}, PreparedSQL: make([]string, 0, 100), } db.cacheStore.Store("preparedStmt", preparedStmt) diff --git a/prepare_stmt.go b/prepare_stmt.go index 14a6aaec..eddee1f2 100644 --- a/prepare_stmt.go +++ b/prepare_stmt.go @@ -9,7 +9,7 @@ import ( type PreparedStmtDB struct { Stmts map[string]*sql.Stmt PreparedSQL []string - Mux sync.RWMutex + Mux *sync.RWMutex ConnPool }