From 16579e00c6f018af089391ed8540448fc13e047f Mon Sep 17 00:00:00 2001 From: shiyu7 <65223714+shiyu7@users.noreply.github.com> Date: Thu, 1 Jul 2021 06:27:12 +0800 Subject: [PATCH] fix: fix race issue in prepare method (#4487) --- prepare_stmt.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prepare_stmt.go b/prepare_stmt.go index 14570061..48a614b7 100644 --- a/prepare_stmt.go +++ b/prepare_stmt.go @@ -64,7 +64,7 @@ func (db *PreparedStmtDB) prepare(ctx context.Context, conn ConnPool, isTransact db.Stmts[query] = Stmt{Stmt: stmt, Transaction: isTransaction} db.PreparedSQL = append(db.PreparedSQL, query) } - db.Mux.Unlock() + defer db.Mux.Unlock() return db.Stmts[query], err }