Skip to content

Commit

Permalink
ConnPool.Begin/BeginIso will retry if they Acquire a dead connection
Browse files Browse the repository at this point in the history
  • Loading branch information
josephglanville committed Sep 10, 2015
1 parent 8b296b9 commit 4868929
Showing 1 changed file with 32 additions and 20 deletions.
52 changes: 32 additions & 20 deletions conn_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,34 +214,46 @@ func (p *ConnPool) QueryRow(sql string, args ...interface{}) *Row {
// Begin acquires a connection and begins a transaction on it. When the
// transaction is closed the connection will be automatically released.
func (p *ConnPool) Begin() (*Tx, error) {
c, err := p.Acquire()
if err != nil {
return nil, err
}
for {
c, err := p.Acquire()
if err != nil {
return nil, err
}

tx, err := c.Begin()
if err != nil {
return nil, err
}
tx, err := c.Begin()
if err == ErrDeadConn {
p.Release(c)
continue
}
if err != nil {
return nil, err
}

tx.pool = p
return tx, nil
tx.pool = p
return tx, nil
}
}

// BeginIso acquires a connection and begins a transaction in isolation mode iso
// on it. When the transaction is closed the connection will be automatically
// released.
func (p *ConnPool) BeginIso(iso string) (*Tx, error) {
c, err := p.Acquire()
if err != nil {
return nil, err
}
for {
c, err := p.Acquire()
if err != nil {
return nil, err
}

tx, err := c.BeginIso(iso)
if err != nil {
return nil, err
}
tx, err := c.BeginIso(iso)
if err == ErrDeadConn {
p.Release(c)
continue
}
if err != nil {
return nil, err
}

tx.pool = p
return tx, nil
tx.pool = p
return tx, nil
}
}

0 comments on commit 4868929

Please sign in to comment.