mirror of https://github.com/go-gorm/gorm.git
Fix hang when closing a prepared statement
This commit is contained in:
parent
ac97aec513
commit
74752018dc
|
@ -35,7 +35,7 @@ func (db *PreparedStmtDB) Close() {
|
||||||
for _, query := range db.PreparedSQL {
|
for _, query := range db.PreparedSQL {
|
||||||
if stmt, ok := db.Stmts[query]; ok {
|
if stmt, ok := db.Stmts[query]; ok {
|
||||||
delete(db.Stmts, query)
|
delete(db.Stmts, query)
|
||||||
stmt.Close()
|
go stmt.Close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ func (db *PreparedStmtDB) prepare(ctx context.Context, conn ConnPool, isTransact
|
||||||
db.Mux.Unlock()
|
db.Mux.Unlock()
|
||||||
return stmt, nil
|
return stmt, nil
|
||||||
} else if ok {
|
} else if ok {
|
||||||
stmt.Close()
|
go stmt.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
stmt, err := conn.PrepareContext(ctx, query)
|
stmt, err := conn.PrepareContext(ctx, query)
|
||||||
|
@ -83,7 +83,7 @@ func (db *PreparedStmtDB) ExecContext(ctx context.Context, query string, args ..
|
||||||
result, err = stmt.ExecContext(ctx, args...)
|
result, err = stmt.ExecContext(ctx, args...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
db.Mux.Lock()
|
db.Mux.Lock()
|
||||||
stmt.Close()
|
go stmt.Close()
|
||||||
delete(db.Stmts, query)
|
delete(db.Stmts, query)
|
||||||
db.Mux.Unlock()
|
db.Mux.Unlock()
|
||||||
}
|
}
|
||||||
|
@ -97,7 +97,7 @@ func (db *PreparedStmtDB) QueryContext(ctx context.Context, query string, args .
|
||||||
rows, err = stmt.QueryContext(ctx, args...)
|
rows, err = stmt.QueryContext(ctx, args...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
db.Mux.Lock()
|
db.Mux.Lock()
|
||||||
stmt.Close()
|
go stmt.Close()
|
||||||
delete(db.Stmts, query)
|
delete(db.Stmts, query)
|
||||||
db.Mux.Unlock()
|
db.Mux.Unlock()
|
||||||
}
|
}
|
||||||
|
@ -138,7 +138,7 @@ func (tx *PreparedStmtTX) ExecContext(ctx context.Context, query string, args ..
|
||||||
result, err = tx.Tx.StmtContext(ctx, stmt.Stmt).ExecContext(ctx, args...)
|
result, err = tx.Tx.StmtContext(ctx, stmt.Stmt).ExecContext(ctx, args...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tx.PreparedStmtDB.Mux.Lock()
|
tx.PreparedStmtDB.Mux.Lock()
|
||||||
stmt.Close()
|
go stmt.Close()
|
||||||
delete(tx.PreparedStmtDB.Stmts, query)
|
delete(tx.PreparedStmtDB.Stmts, query)
|
||||||
tx.PreparedStmtDB.Mux.Unlock()
|
tx.PreparedStmtDB.Mux.Unlock()
|
||||||
}
|
}
|
||||||
|
@ -152,7 +152,7 @@ func (tx *PreparedStmtTX) QueryContext(ctx context.Context, query string, args .
|
||||||
rows, err = tx.Tx.Stmt(stmt.Stmt).QueryContext(ctx, args...)
|
rows, err = tx.Tx.Stmt(stmt.Stmt).QueryContext(ctx, args...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tx.PreparedStmtDB.Mux.Lock()
|
tx.PreparedStmtDB.Mux.Lock()
|
||||||
stmt.Close()
|
go stmt.Close()
|
||||||
delete(tx.PreparedStmtDB.Stmts, query)
|
delete(tx.PreparedStmtDB.Stmts, query)
|
||||||
tx.PreparedStmtDB.Mux.Unlock()
|
tx.PreparedStmtDB.Mux.Unlock()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue