mirror of https://github.com/jackc/pgx.git
ConnPool.Begin/BeginIso will retry if they Acquire a dead connection
parent
8b296b9d58
commit
4868929ff1
52
conn_pool.go
52
conn_pool.go
|
@ -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
|
// Begin acquires a connection and begins a transaction on it. When the
|
||||||
// transaction is closed the connection will be automatically released.
|
// transaction is closed the connection will be automatically released.
|
||||||
func (p *ConnPool) Begin() (*Tx, error) {
|
func (p *ConnPool) Begin() (*Tx, error) {
|
||||||
c, err := p.Acquire()
|
for {
|
||||||
if err != nil {
|
c, err := p.Acquire()
|
||||||
return nil, err
|
if err != nil {
|
||||||
}
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
tx, err := c.Begin()
|
tx, err := c.Begin()
|
||||||
if err != nil {
|
if err == ErrDeadConn {
|
||||||
return nil, err
|
p.Release(c)
|
||||||
}
|
continue
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
tx.pool = p
|
tx.pool = p
|
||||||
return tx, nil
|
return tx, nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// BeginIso acquires a connection and begins a transaction in isolation mode iso
|
// BeginIso acquires a connection and begins a transaction in isolation mode iso
|
||||||
// on it. When the transaction is closed the connection will be automatically
|
// on it. When the transaction is closed the connection will be automatically
|
||||||
// released.
|
// released.
|
||||||
func (p *ConnPool) BeginIso(iso string) (*Tx, error) {
|
func (p *ConnPool) BeginIso(iso string) (*Tx, error) {
|
||||||
c, err := p.Acquire()
|
for {
|
||||||
if err != nil {
|
c, err := p.Acquire()
|
||||||
return nil, err
|
if err != nil {
|
||||||
}
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
tx, err := c.BeginIso(iso)
|
tx, err := c.BeginIso(iso)
|
||||||
if err != nil {
|
if err == ErrDeadConn {
|
||||||
return nil, err
|
p.Release(c)
|
||||||
}
|
continue
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
tx.pool = p
|
tx.pool = p
|
||||||
return tx, nil
|
return tx, nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue