fix: avoid coroutine leaks when the dialecter initialization fails. (#6249)

Co-authored-by: Kevin Lin <kevin.lin@shopee.com>
This commit is contained in:
Zhiheng Lin 2023-04-21 22:17:21 +08:00 committed by GitHub
parent ac20d9e222
commit 32fc201554
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 0 deletions

View File

@ -179,6 +179,12 @@ func Open(dialector Dialector, opts ...Option) (db *DB, err error) {
if config.Dialector != nil { if config.Dialector != nil {
err = config.Dialector.Initialize(db) err = config.Dialector.Initialize(db)
if err != nil {
if db, err := db.DB(); err == nil {
_ = db.Close()
}
}
} }
preparedStmt := &PreparedStmtDB{ preparedStmt := &PreparedStmtDB{