Skip to content

Commit

Permalink
[release-branch.go1.10] database/sql: check for nil connRequest.conn …
Browse files Browse the repository at this point in the history
…before use

The connRequest may return a nil conn value. However in a rare
case that is difficult to test for it was being passed to
DB.putConn without a nil check. This was an error as this
made no sense if the driverConn is nil. This also caused
a panic in putConn.

A test for this would be nice, but didn't find a sane
way to test for this condition.

Updates #24445
Fixes #25235

Change-Id: I827316e856788a5a3ced913f129bb5869b7bcf68
Reviewed-on: https://go-review.googlesource.com/102477
Run-TryBot: Daniel Theophanes <kardianos@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alexey Palazhchenko <alexey.palazhchenko@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
(cherry picked from commit b98ffdf)
Reviewed-on: https://go-review.googlesource.com/c/146778
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Katie Hockman <katie@golang.org>
  • Loading branch information
kardianos authored and bradfitz committed Nov 1, 2018
1 parent fba2c4d commit edd28f1
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/database/sql/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -1070,7 +1070,7 @@ func (db *DB) conn(ctx context.Context, strategy connReuseStrategy) (*driverConn
select {
default:
case ret, ok := <-req:
if ok {
if ok && ret.conn != nil {
db.putConn(ret.conn, ret.err, false)
}
}
Expand Down

0 comments on commit edd28f1

Please sign in to comment.