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:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user