mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
database/sql: don't close a driver.Conn until its Stmts are closed
Fixes #5046 R=golang-dev, r CC=golang-dev https://golang.org/cl/8016044
This commit is contained in:
parent
f20f8b8b0a
commit
209f6b1d2c
3 changed files with 137 additions and 20 deletions
|
|
@ -229,7 +229,26 @@ func (c *fakeConn) Begin() (driver.Tx, error) {
|
|||
return c.currTx, nil
|
||||
}
|
||||
|
||||
func (c *fakeConn) Close() error {
|
||||
var hookPostCloseConn struct {
|
||||
sync.Mutex
|
||||
fn func(*fakeConn, error)
|
||||
}
|
||||
|
||||
func setHookpostCloseConn(fn func(*fakeConn, error)) {
|
||||
hookPostCloseConn.Lock()
|
||||
defer hookPostCloseConn.Unlock()
|
||||
hookPostCloseConn.fn = fn
|
||||
}
|
||||
|
||||
func (c *fakeConn) Close() (err error) {
|
||||
defer func() {
|
||||
hookPostCloseConn.Lock()
|
||||
fn := hookPostCloseConn.fn
|
||||
hookPostCloseConn.Unlock()
|
||||
if fn != nil {
|
||||
fn(c, err)
|
||||
}
|
||||
}()
|
||||
if c.currTx != nil {
|
||||
return errors.New("can't close fakeConn; in a Transaction")
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue