Skip to content

Commit

Permalink
fix: avoid coroutine leaks when the dialecter initialization fails. (#…
Browse files Browse the repository at this point in the history
…6249)

Co-authored-by: Kevin Lin <[email protected]>
  • Loading branch information
onlyice and Kevin Lin committed Apr 21, 2023
1 parent ac20d9e commit 32fc201
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions gorm.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,12 @@ func Open(dialector Dialector, opts ...Option) (db *DB, err error) {

if config.Dialector != nil {
err = config.Dialector.Initialize(db)

if err != nil {
if db, err := db.DB(); err == nil {
_ = db.Close()
}
}
}

preparedStmt := &PreparedStmtDB{
Expand Down

0 comments on commit 32fc201

Please sign in to comment.