mirror of https://github.com/jackc/pgx.git
ConnPool begin should not retry if ctx is done
parent
152dbffa4a
commit
9530d7fa4c
|
@ -519,7 +519,7 @@ func (p *ConnPool) BeginEx(ctx context.Context, txOptions *TxOptions) (*Tx, erro
|
||||||
// again on a new connection would fix, so just return the error. But
|
// 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
|
// if the connection is dead try to acquire a new connection and try
|
||||||
// again.
|
// again.
|
||||||
if alive {
|
if alive || ctx.Err() != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -1066,3 +1066,18 @@ func TestConnPoolBeginBatch(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestConnPoolBeginEx(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
pool := createConnPool(t, 2)
|
||||||
|
defer pool.Close()
|
||||||
|
|
||||||
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
cancel()
|
||||||
|
|
||||||
|
tx, err := pool.BeginEx(ctx, nil)
|
||||||
|
if err == nil || tx != nil {
|
||||||
|
t.Fatal("Should not be able to create a tx")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue