mirror of
https://github.com/jackc/pgx.git
synced 2025-05-31 11:42:24 +00:00
ConnPool.Begin retry logic checks connection IsAlive
ErrDeadConn is returned when calling an already dead connection. But the initial failure returns the real error. So we check for IsAlive instead of ErrDeadConn. Added test for ConnPool.Begin retry logic.
This commit is contained in:
parent
6e5fa60c4c
commit
93aa2b2e80
14
conn_pool.go
14
conn_pool.go
@ -228,13 +228,19 @@ func (p *ConnPool) BeginIso(iso string) (*Tx, error) {
|
||||
}
|
||||
|
||||
tx, err := c.BeginIso(iso)
|
||||
if err == ErrDeadConn {
|
||||
if err != nil {
|
||||
alive := c.IsAlive()
|
||||
p.Release(c)
|
||||
|
||||
// If connection is still alive then the error is not something trying
|
||||
// again on a new connection would fix, so just return the error. But
|
||||
// if the connection is dead try to acquire a new connection and try
|
||||
// again.
|
||||
if alive {
|
||||
return nil, err
|
||||
} else {
|
||||
continue
|
||||
}
|
||||
if err != nil {
|
||||
p.Release(c)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
tx.pool = p
|
||||
|
@ -363,6 +363,9 @@ func TestConnPoolTransactionIso(t *testing.T) {
|
||||
func TestConnPoolBeginRetry(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Run timing sensitive test many times
|
||||
for i := 0; i < 50; i++ {
|
||||
func() {
|
||||
pool := createConnPool(t, 2)
|
||||
defer pool.Close()
|
||||
|
||||
@ -399,6 +402,8 @@ func TestConnPoolBeginRetry(t *testing.T) {
|
||||
if txPid == victimConn.Pid {
|
||||
t.Error("Expected txPid to defer from killed conn pid, but it didn't")
|
||||
}
|
||||
}()
|
||||
}
|
||||
}
|
||||
|
||||
func TestConnPoolQuery(t *testing.T) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user