Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions multipool.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ func NewMultiPool(size, sizePerPool int, lbs LoadBalancingStrategy, options ...O
for i := 0; i < size; i++ {
pool, err := NewPool(sizePerPool, options...)
if err != nil {
// Release all previously created pools to avoid resource leak
for j := 0; j < i; j++ {
pools[j].Release()
}
return nil, err
}
pools[i] = pool
Expand Down
4 changes: 4 additions & 0 deletions multipool_func.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ func NewMultiPoolWithFunc(size, sizePerPool int, fn func(any), lbs LoadBalancing
for i := 0; i < size; i++ {
pool, err := NewPoolWithFunc(sizePerPool, fn, options...)
if err != nil {
// Release all previously created pools to avoid resource leak
for j := 0; j < i; j++ {
pools[j].Release()
}
return nil, err
}
pools[i] = pool
Expand Down
4 changes: 4 additions & 0 deletions multipool_func_generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ func NewMultiPoolWithFuncGeneric[T any](size, sizePerPool int, fn func(T), lbs L
for i := 0; i < size; i++ {
pool, err := NewPoolWithFuncGeneric(sizePerPool, fn, options...)
if err != nil {
// Release all previously created pools to avoid resource leak
for j := 0; j < i; j++ {
pools[j].Release()
}
return nil, err
}
pools[i] = pool
Expand Down
Loading