database/sql: Fix connection leak and potential deadlock

CL 10726044 introduced a race condition which causes connections
to be leaked under certain circumstances. If SetMaxOpenConns is
used, the application eventually deadlocks. Otherwise, the number
of open connections just keep growing indefinitely.

Fixes issue 6593

R=golang-dev, bradfitz, tad.glines, bketelsen
CC=golang-dev
https://codereview.appspot.com/14611045

Committer: Brad Fitzpatrick <bradfitz@golang.org>