Merge pull request #357 from plopik/master

ConnPool begin should not retry if ctx is done
pull/358/head
Jack Christensen 2017-11-22 08:00:28 -06:00 committed by GitHub
commit e3c5552ff1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 1 deletions

View File

@ -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
// if the connection is dead try to acquire a new connection and try
// again.
if alive {
if alive || ctx.Err() != nil {
return nil, err
}
continue

View File

@ -1066,3 +1066,18 @@ func TestConnPoolBeginBatch(t *testing.T) {
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")
}
}