diff --git a/pool.go b/pool.go index e18658c..f9190d6 100644 --- a/pool.go +++ b/pool.go @@ -427,8 +427,12 @@ func (p *Pool[T]) initResourceValue(ctx context.Context, res *Resource[T]) (*Res return } + // The resource is already in p.allResources where it might be read. So we need to acquire the lock to update its + // status. + p.mux.Lock() res.value = value res.status = resourceStatusAcquired + p.mux.Unlock() // This select works because the channel is unbuffered. select { diff --git a/pool_test.go b/pool_test.go index 45ee822..ac0d15b 100644 --- a/pool_test.go +++ b/pool_test.go @@ -985,6 +985,11 @@ func TestStress(t *testing.T) { res.Release() } }, + // Stat + func() { + stat := pool.Stat() + assert.NotNil(t, stat) + }, } workerCount := int(poolSize) * 2