mirror of
https://github.com/golang/go
synced 2024-11-12 02:20:23 -07:00
sql: fix missing mutex unlock in an error case
Fixes #2542 R=golang-dev, r CC=golang-dev https://golang.org/cl/5483054
This commit is contained in:
parent
3dc278d3e2
commit
06a9bc6835
@ -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")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user