mirror of
https://github.com/golang/go
synced 2024-11-26 18:06:55 -07:00
database/sql: close statement before connection
Fixes #5936 R=golang-dev, bradfitz CC=golang-dev https://golang.org/cl/11620046
This commit is contained in:
parent
abe384f68a
commit
a293065a39
@ -759,10 +759,10 @@ func (db *DB) queryConn(dc *driverConn, releaseConn func(error), query string, a
|
|||||||
ds := driverStmt{dc, si}
|
ds := driverStmt{dc, si}
|
||||||
rowsi, err := rowsiFromStatement(ds, args...)
|
rowsi, err := rowsiFromStatement(ds, args...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
releaseConn(err)
|
|
||||||
dc.Lock()
|
dc.Lock()
|
||||||
si.Close()
|
si.Close()
|
||||||
dc.Unlock()
|
dc.Unlock()
|
||||||
|
releaseConn(err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1046,6 +1046,20 @@ func TestRowsCloseOrder(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestStmtCloseOrder(t *testing.T) {
|
||||||
|
db := newTestDB(t, "people")
|
||||||
|
defer closeDB(t, db)
|
||||||
|
|
||||||
|
db.SetMaxIdleConns(0)
|
||||||
|
setStrictFakeConnClose(t)
|
||||||
|
defer setStrictFakeConnClose(nil)
|
||||||
|
|
||||||
|
_, err := db.Query("SELECT|non_existent|name|")
|
||||||
|
if err == nil {
|
||||||
|
t.Fatal("Quering non-existent table should fail")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func manyConcurrentQueries(t testOrBench) {
|
func manyConcurrentQueries(t testOrBench) {
|
||||||
maxProcs, numReqs := 16, 500
|
maxProcs, numReqs := 16, 500
|
||||||
if testing.Short() {
|
if testing.Short() {
|
||||||
|
Loading…
Reference in New Issue
Block a user