2
0

Fix data race with Rows and ConnPool

In an effort to reduce memory allocations, Rows was stored on the
Conn. This caused a race condition where Rows are closed and this
returns the Conn to the Pool. The Pool could then give out the Conn
again. Rows would then be reanimated and the original Rows could reclose
it.
This commit is contained in:
Brian Dunn and Jack Christensen
2014-09-16 16:29:45 -05:00
parent a5f082fa03
commit a68115fc03
3 changed files with 45 additions and 3 deletions
+1 -2
View File
@@ -354,8 +354,7 @@ func (rows *Rows) Values() ([]interface{}, error) {
// be returned in an error state. So it is allowed to ignore the error returned
// from Query and handle it in *Rows.
func (c *Conn) Query(sql string, args ...interface{}) (*Rows, error) {
c.rows = Rows{conn: c, startTime: time.Now(), sql: sql, args: args, logger: c.logger}
rows := &c.rows
rows := &Rows{conn: c, startTime: time.Now(), sql: sql, args: args, logger: c.logger}
ps, ok := c.preparedStatements[sql]
if !ok {