提交 decc75e0 编写于 作者: J jianzhiyao

fix bug of non concurrent security & add double check

上级 81600591
......@@ -120,17 +120,24 @@ func (d *DB) BeginTx(ctx context.Context, opts *sql.TxOptions) (*sql.Tx, error)
func (d *DB) getStmt(query string) (*sql.Stmt, error) {
d.RLock()
if stmt, ok := d.stmts[query]; ok {
d.RUnlock()
return stmt, nil
}
c, ok := d.stmts[query]
d.RUnlock()
if ok {
return c, nil
}
d.Lock()
c, ok = d.stmts[query]
if ok {
d.Unlock()
return c, nil
}
stmt, err := d.Prepare(query)
if err != nil {
d.Unlock()
return nil, err
}
d.Lock()
d.stmts[query] = stmt
d.Unlock()
return stmt, nil
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册