mirror of
https://github.com/golang/go
synced 2024-11-27 03:21:18 -07:00
[release-branch.go1.8] database/sql: ensure releaseConn is defined before a possible close
Applies https://golang.org/cl/42139 to the go1.8 release branch. Also correct two minor issues detected with go vet. Fixes #20217 Change-Id: I2c41af9497493598fbcfc140439b4e25b9bb7e72 Reviewed-on: https://go-review.googlesource.com/42532 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Chris Broadfoot <cbro@golang.org>
This commit is contained in:
parent
fb9770f09b
commit
6efa2f22ac
@ -1955,12 +1955,12 @@ func (s *Stmt) QueryContext(ctx context.Context, args ...interface{}) (*Rows, er
|
||||
rowsi: rowsi,
|
||||
// releaseConn set below
|
||||
}
|
||||
rows.initContextClose(ctx)
|
||||
s.db.addDep(s, rows)
|
||||
rows.releaseConn = func(err error) {
|
||||
releaseConn(err)
|
||||
s.db.removeDep(s, rows)
|
||||
}
|
||||
rows.initContextClose(ctx)
|
||||
return rows, nil
|
||||
}
|
||||
|
||||
|
@ -322,7 +322,7 @@ func TestQueryContext(t *testing.T) {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
if err := ctx.Err(); err != context.Canceled {
|
||||
t.Fatalf("context err = %v; want context.Canceled")
|
||||
t.Fatalf("context err = %v; want context.Canceled", ctx.Err())
|
||||
}
|
||||
default:
|
||||
t.Fatalf("context err = nil; want context.Canceled")
|
||||
@ -413,7 +413,8 @@ func TestTxContextWait(t *testing.T) {
|
||||
db := newTestDB(t, "people")
|
||||
defer closeDB(t, db)
|
||||
|
||||
ctx, _ := context.WithTimeout(context.Background(), time.Millisecond*15)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Millisecond*15)
|
||||
defer cancel()
|
||||
|
||||
tx, err := db.BeginTx(ctx, nil)
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user