Commit 06a9bc68 authored by Brad Fitzpatrick's avatar Brad Fitzpatrick

sql: fix missing mutex unlock in an error case

Fixes #2542

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/5483054
parent 3dc278d3
......@@ -134,6 +134,7 @@ func (db *DB) maxIdleConns() int {
func (db *DB) conn() (driver.Conn, error) {
db.mu.Lock()
if db.closed {
db.mu.Unlock()
return nil, errors.New("sql: database is closed")
}
if n := len(db.freeConn); n > 0 {
......
......@@ -228,3 +228,16 @@ func TestTxStmt(t *testing.T) {
t.Fatalf("Commit = %v", err)
}
}
// Tests fix for issue 2542, that we release a lock when querying on
// a closed connection.
func TestIssue2542Deadlock(t *testing.T) {
db := newTestDB(t, "people")
closeDB(t, db)
for i := 0; i < 2; i++ {
_, err := db.Query("SELECT|people|age,name|")
if err == nil {
t.Fatalf("expected error")
}
}
}
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