From 36d3bef8a3b2a3b7b2662e5b2fd7abbf70c47114 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Mon, 15 Apr 2013 14:06:41 -0700 Subject: database/sql: close driver Stmt before releasing Conn From the issue, which describes it as well as I could: database/sql assumes that driver.Stmt.Close does not need the connection. see database/sql/sql.go:1308: This puts the Rows' connection back into the idle pool, and then calls the driver.Stmt.Close method of the Stmt it belongs to. In the postgresql driver implementation (https://github.com/lib/pq), Stmt.Close communicates with the server (on the connection that was just put back into the idle pool). Most of the time, this causes no problems, but if another goroutine makes a query at the right (wrong?) time, chaos results. In any case, traffic is being sent on "free" connections shortly after they are freed, leading to race conditions that kill the driver code. Fixes #5283 R=golang-dev, r CC=golang-dev https://golang.org/cl/8633044 --- src/pkg/database/sql/sql.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/pkg/database/sql/sql.go') diff --git a/src/pkg/database/sql/sql.go b/src/pkg/database/sql/sql.go index bd450c7ec9..72289407c9 100644 --- a/src/pkg/database/sql/sql.go +++ b/src/pkg/database/sql/sql.go @@ -1311,10 +1311,10 @@ func (rs *Rows) Close() error { } rs.closed = true err := rs.rowsi.Close() - rs.releaseConn(err) if rs.closeStmt != nil { rs.closeStmt.Close() } + rs.releaseConn(err) return err } -- cgit v1.3