diff options
| author | Chris Hines <chris.cs.guy@gmail.com> | 2015-08-24 21:48:39 -0400 |
|---|---|---|
| committer | Brad Fitzpatrick <bradfitz@golang.org> | 2015-09-03 17:07:37 +0000 |
| commit | d737639c4acce7c9f28de22eabfd623d0ae7ed50 (patch) | |
| tree | 66e0ab6142e55f89a25cebe74f126405bac6c34f /src/database/sql/sql.go | |
| parent | bf99d8f843ae3dfa7a3a4cd5c17aec79e2b9997f (diff) | |
| download | go-d737639c4acce7c9f28de22eabfd623d0ae7ed50.tar.xz | |
database/sql: close bad connections in commit or rollback:
Previously Tx.close always passed a nil error to tx.db.putConn. As a
result bad connections were reused, even if the driver returned
driver.ErrBadConn. Adding an err parameter to Tx.close allows it to
receive the driver error from Tx.Commit and Tx.Rollback and pass it
to tx.db.putConn.
Fixes #11264
Change-Id: I142b6b2509fa8d714bbc135cef7281a40803b3b8
Reviewed-on: https://go-review.googlesource.com/13912
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/database/sql/sql.go')
| -rw-r--r-- | src/database/sql/sql.go | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/database/sql/sql.go b/src/database/sql/sql.go index aaa4ea28be..0120ae8abe 100644 --- a/src/database/sql/sql.go +++ b/src/database/sql/sql.go @@ -1103,12 +1103,12 @@ type Tx struct { var ErrTxDone = errors.New("sql: Transaction has already been committed or rolled back") -func (tx *Tx) close() { +func (tx *Tx) close(err error) { if tx.done { panic("double close") // internal error } tx.done = true - tx.db.putConn(tx.dc, nil) + tx.db.putConn(tx.dc, err) tx.dc = nil tx.txi = nil } @@ -1134,13 +1134,13 @@ func (tx *Tx) Commit() error { if tx.done { return ErrTxDone } - defer tx.close() tx.dc.Lock() err := tx.txi.Commit() tx.dc.Unlock() if err != driver.ErrBadConn { tx.closePrepared() } + tx.close(err) return err } @@ -1149,13 +1149,13 @@ func (tx *Tx) Rollback() error { if tx.done { return ErrTxDone } - defer tx.close() tx.dc.Lock() err := tx.txi.Rollback() tx.dc.Unlock() if err != driver.ErrBadConn { tx.closePrepared() } + tx.close(err) return err } |
