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 or closing in progress to make
the behavior deterministic.
  • Loading branch information
oleg-jukovec committed Dec 11, 2024
1 parent ebdf986 commit dba8c85
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pool/connection_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,13 @@ func (p *ConnectionPool) Add(ctx context.Context, instance Instance) error {
canceled = false
}
if canceled {
if p.state.get() != connectedState {
// If it is canceled (or could be canceled) 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 dba8c85

Please sign in to comment.