diff options
| author | Alberto GarcĂa Hierro <alberto@garciahierro.com> | 2013-10-16 09:22:57 -0700 |
|---|---|---|
| committer | Brad Fitzpatrick <bradfitz@golang.org> | 2013-10-16 09:22:57 -0700 |
| commit | 37db8804691f0a5e618cbc041909895c9709263c (patch) | |
| tree | b8e0c739848eec66cdc69f4636f15751370c191b /src/pkg/database/sql/sql.go | |
| parent | 478f4b67543824c039d2f7afec6af88a59148db2 (diff) | |
| download | go-37db8804691f0a5e618cbc041909895c9709263c.tar.xz | |
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 #6593
R=golang-dev, bradfitz, tad.glines, bketelsen
CC=golang-dev
https://golang.org/cl/14611045
Diffstat (limited to 'src/pkg/database/sql/sql.go')
| -rw-r--r-- | src/pkg/database/sql/sql.go | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/pkg/database/sql/sql.go b/src/pkg/database/sql/sql.go index fe46ff3781..3047735acc 100644 --- a/src/pkg/database/sql/sql.go +++ b/src/pkg/database/sql/sql.go @@ -593,9 +593,12 @@ func (db *DB) openNewConnection() { db: db, ci: ci, } - db.addDepLocked(dc, dc) - db.numOpen++ - db.putConnDBLocked(dc, err) + if db.putConnDBLocked(dc, err) { + db.addDepLocked(dc, dc) + db.numOpen++ + } else { + ci.Close() + } } // connRequest represents one request for a new connection |
