Add to the destructWG wait group while cond.L is locked
Otherwise, if many constructors are underway while the pool is closed it is possible destructWG will get to 0 while the Wait in Close is underway and then Add will be called again which is disallowed. From the docs: Note that calls with a positive delta that occur when the counter is zero must happen before a Wait. https://github.com/jackc/pgx/issues/1356
This commit is contained in:
@@ -496,10 +496,12 @@ func (p *Pool[T]) CreateResource(ctx context.Context) error {
|
||||
p.cond.L.Unlock()
|
||||
return ErrClosedPool
|
||||
}
|
||||
p.destructWG.Add(1)
|
||||
p.cond.L.Unlock()
|
||||
|
||||
value, err := p.constructResourceValue(ctx)
|
||||
if err != nil {
|
||||
p.destructWG.Done()
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -511,7 +513,6 @@ func (p *Pool[T]) CreateResource(ctx context.Context) error {
|
||||
lastUsedNano: nanotime(),
|
||||
poolResetCount: p.resetCount,
|
||||
}
|
||||
p.destructWG.Add(1)
|
||||
|
||||
p.cond.L.Lock()
|
||||
// If closed while constructing resource then destroy it and return an error
|
||||
|
||||
Reference in New Issue
Block a user