Skip to content

Commit dba8c85

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 or closing in progress to make the behavior deterministic.
1 parent ebdf986 commit dba8c85

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

pool/connection_pool.go

+7
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,13 @@ 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 canceled (or could be canceled) due to a
288+
// Close()/CloseGraceful() call we overwrite the error
289+
// to make behavior expected.
290+
err = ErrClosed
291+
}
292+
286293
p.endsMutex.Lock()
287294
delete(p.ends, instance.Name)
288295
p.endsMutex.Unlock()

0 commit comments

Comments
 (0)