Skip to content

Commit e3db7c2

Browse files
committed
test: fix flaky TestAdd_Close_concurrent
We need to reset an error to pool.ErrClosed in a Pool.Add() method if a pool already closed to make the behavior deterministic.
1 parent ebdf986 commit e3db7c2

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

pool/connection_pool.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,12 @@ func (p *ConnectionPool) Add(ctx context.Context, instance Instance) error {
283283
canceled = false
284284
}
285285
if canceled {
286+
if p.state.get() != connectedState {
287+
// If it is cancelled due to a Close()/CloseGraceful call we
288+
// overwrite the error to make behavior expected.
289+
err = ErrClosed
290+
}
291+
286292
p.endsMutex.Lock()
287293
delete(p.ends, instance.Name)
288294
p.endsMutex.Unlock()

0 commit comments

Comments
 (0)