From 74752018dcf9c07d95dace4bb2b98b3b169fad0f Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Wed, 14 Jul 2021 18:31:50 +0800 Subject: [PATCH] Fix hang when closing a prepared statement --- prepare_stmt.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/prepare_stmt.go b/prepare_stmt.go index 48a614b7..5faea995 100644 --- a/prepare_stmt.go +++ b/prepare_stmt.go @@ -35,7 +35,7 @@ func (db *PreparedStmtDB) Close() { for _, query := range db.PreparedSQL { if stmt, ok := db.Stmts[query]; ok { 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() return stmt, nil } else if ok { - stmt.Close() + go stmt.Close() } 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...) if err != nil { db.Mux.Lock() - stmt.Close() + go stmt.Close() delete(db.Stmts, query) db.Mux.Unlock() } @@ -97,7 +97,7 @@ func (db *PreparedStmtDB) QueryContext(ctx context.Context, query string, args . rows, err = stmt.QueryContext(ctx, args...) if err != nil { db.Mux.Lock() - stmt.Close() + go stmt.Close() delete(db.Stmts, query) 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...) if err != nil { tx.PreparedStmtDB.Mux.Lock() - stmt.Close() + go stmt.Close() delete(tx.PreparedStmtDB.Stmts, query) 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...) if err != nil { tx.PreparedStmtDB.Mux.Lock() - stmt.Close() + go stmt.Close() delete(tx.PreparedStmtDB.Stmts, query) tx.PreparedStmtDB.Mux.Unlock() }