Skip to content

Commit

Permalink
Clone the Default logger when opening (jinzhu#10)
Browse files Browse the repository at this point in the history
* Clone the Default logger when opening

This fixes a data race when multiple gorm connections are being created simultaneously.

* Update main.go
  • Loading branch information
sethvargo authored Sep 15, 2020
1 parent 6f4358e commit 6bc389d
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ func Open(dialect string, args ...interface{}) (db *DB, err error) {
db = &DB{
db: dbSQL,
logger: defaultLogger,
callbacks: DefaultCallback,

// Create a clone of the default logger to avoid mutating a shared object when
// multiple gorm connections are created simultaneously.
callbacks: DefaultCallback.clone(defaultLogger),
dialect: newDialect(dialect, dbSQL),
}
db.parent = db
Expand Down

0 comments on commit 6bc389d

Please sign in to comment.