Commit 6efa2f22 authored by Daniel Theophanes's avatar Daniel Theophanes Committed by Chris Broadfoot

[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: 's avatarChris Broadfoot <cbro@golang.org>
parent fb9770f0
......@@ -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 {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment