Closed
Description
Problem
Whenever eviction and close run at the same time. There is a possible deadlock because of the closeLock mutex usage on poo.go:487. We can unlock it whenever we don't need it rather than using defer.
Repreduce UT
func (suit *PoolTestSuite) TestConcurrentCloseAndEvict() {
ctx := context.Background()
suit.pool.Config.MinIdle = 1
suit.pool.Config.SoftMinEvictableIdleTime = time.Millisecond * 100
suit.pool.Config.TimeBetweenEvictionRuns = time.Millisecond * 500
suit.factory.destroyLatency = time.Millisecond * 1000 // Destroy takes 1000 ms
suit.pool.PreparePool(ctx)
suit.pool.StartEvictor()
suit.Equal(1, suit.pool.GetNumIdle())
ticker := time.NewTicker(time.Millisecond * 1000)
testTimeoutTicker := time.NewTicker(time.Millisecond * 5000) // if time exceeds test fails
go func() {
select {
case <-testTimeoutTicker.C:
// Time-out
suit.FailNow("Time is exceeds on pool close")
}
}()
select {
case <-ticker.C:
suit.pool.Close(ctx)
}
}
Activity