Skip to content

Commit

Permalink
test: fix flaky TestAdd_Close_concurrent
Browse files Browse the repository at this point in the history
We need to reset an error to pool.ErrClosed in a Pool.Add()
method if a pool already closed to make the behavior
deterministic.
  • Loading branch information
oleg-jukovec committed Dec 10, 2024
1 parent ebdf986 commit 0d16dcf
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pool/connection_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,12 @@ func (p *ConnectionPool) Add(ctx context.Context, instance Instance) error {
canceled = false
}
if canceled {
if p.state.get() != connectedState {
// If it is cancelled due to a Close()/CloseGraceful() call we
// overwrite the error to make behavior expected.
err = ErrClosed
}

p.endsMutex.Lock()
delete(p.ends, instance.Name)
p.endsMutex.Unlock()
Expand Down

0 comments on commit 0d16dcf

Please sign in to comment.