mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
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
This commit is contained in:
parent
478f4b6754
commit
37db880469
3 changed files with 63 additions and 3 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue