MSP-8974 up deps
This commit is contained in:
1 parent
0abaaf740f
commit
a0aafd93b9
602 files changed
+47724
-13295
No files matched your search
+11
@@ -1,3 +1,14 @@
|
||||
# 2.2.4 (November 16, 2026)
|
||||
|
||||
* Fix: Destroy resources when construction started by CreateResource finishes after Close or Reset.
|
||||
Previously, Close could leave a resource counted in pool statistics and Reset could allow a stale resource to be reused. (Harrison Crosse)
|
||||
|
||||
# 2.2.3 (October 5, 2026)
|
||||
|
||||
* Fix: Destroy resources when background construction started by TryAcquire finishes after Close or Reset.
|
||||
Previously, Close could wait indefinitely and Reset could allow a stale resource to be reused. (bensynapse)
|
||||
* Replace custom logarithm calculation with math/bits. (Andy Walker)
|
||||
|
||||
# 2.2.2 (September 10, 2024)
|
||||
|
||||
* Add empty acquire time to stats (Maxim Ivanov)
|
||||
|
||||
+17
-1
@@ -73,7 +73,23 @@ Puddle is stable and feature complete.
|
||||
|
||||
## Supported Go Versions
|
||||
|
||||
puddle supports the same versions of Go that are supported by the Go project. For [Go](https://golang.org/doc/devel/release.html#policy) that is the two most recent major releases. This means puddle supports Go 1.19 and higher.
|
||||
puddle supports the same versions of Go that are supported by the Go project: the [two most recent major releases](https://go.dev/doc/devel/release#policy). The minimum Go version declared in `go.mod` is 1.19, which is also tested in CI as a compatibility baseline.
|
||||
|
||||
## Differences with Go sync.Pool
|
||||
|
||||
They are intended for entirely different types of resources:
|
||||
|
||||
* [sync.Pool](https://pkg.go.dev/sync#Pool) would generally be used for in memory objects.
|
||||
* Puddle would generally be used for handles to external objects such as connections, file handles, etc.
|
||||
|
||||
Specific differences:
|
||||
|
||||
* sync.Pool does not have a way to limit max resources in pool.
|
||||
* sync.Pool does not have a way to ensure at least min resources in pool.
|
||||
* sync.Pool can drop resources in pool at any time - not ideal for expensive to create connections.
|
||||
* sync.Pool does not have a cleanup / release function. Resources are GCed without a chance to close cleanly.
|
||||
* sync.Pool does not have a way to handle errors creating the resource
|
||||
* sync.Pool does not support context to limit time to wait creating a resource
|
||||
|
||||
## License
|
||||
|
||||
|
||||
-32
@@ -1,32 +0,0 @@
|
||||
package puddle
|
||||
|
||||
import "unsafe"
|
||||
|
||||
type ints interface {
|
||||
int | int8 | int16 | int32 | int64 | uint | uint8 | uint16 | uint32 | uint64
|
||||
}
|
||||
|
||||
// log2Int returns log2 of an integer. This function panics if val < 0. For val
|
||||
// == 0, returns 0.
|
||||
func log2Int[T ints](val T) uint8 {
|
||||
if val <= 0 {
|
||||
panic("log2 of non-positive number does not exist")
|
||||
}
|
||||
|
||||
return log2IntRange(val, 0, uint8(8*unsafe.Sizeof(val)))
|
||||
}
|
||||
|
||||
func log2IntRange[T ints](val T, begin, end uint8) uint8 {
|
||||
length := end - begin
|
||||
if length == 1 {
|
||||
return begin
|
||||
}
|
||||
|
||||
delim := begin + length/2
|
||||
mask := T(1) << delim
|
||||
if mask > val {
|
||||
return log2IntRange(val, begin, delim)
|
||||
} else {
|
||||
return log2IntRange(val, delim, end)
|
||||
}
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
[tools]
|
||||
go = "1.27.1"
|
||||
+17
-5
@@ -3,6 +3,7 @@ package puddle
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"math/bits"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
@@ -513,6 +514,11 @@ func (p *Pool[T]) TryAcquire(ctx context.Context) (*Resource[T], error) {
|
||||
}
|
||||
|
||||
res.value = value
|
||||
if p.closed || res.poolResetCount != p.resetCount {
|
||||
p.allResources.remove(res)
|
||||
go p.destructResourceValue(value)
|
||||
return
|
||||
}
|
||||
res.status = resourceStatusIdle
|
||||
p.idleResources.Push(res)
|
||||
}()
|
||||
@@ -543,12 +549,14 @@ func (p *Pool[T]) TryAcquire(ctx context.Context) (*Resource[T], error) {
|
||||
// TODO: Replace this with acquireSem.TryAcquireAll() if it gets to
|
||||
// upstream. https://github.com/golang/sync/pull/19
|
||||
func acquireSemAll(sem *semaphore.Weighted, num int) int {
|
||||
if num <= 0 {
|
||||
panic("aquireSemAll: num <= 0")
|
||||
}
|
||||
if sem.TryAcquire(int64(num)) {
|
||||
return num
|
||||
}
|
||||
|
||||
var acquired int
|
||||
for i := int(log2Int(num)); i >= 0; i-- {
|
||||
for i := bits.Len64(uint64(num)) - 1; i >= 0; i-- {
|
||||
val := 1 << i
|
||||
if sem.TryAcquire(int64(val)) {
|
||||
acquired += val
|
||||
@@ -638,10 +646,14 @@ func (p *Pool[T]) CreateResource(ctx context.Context) error {
|
||||
res.value = value
|
||||
res.status = resourceStatusIdle
|
||||
|
||||
// If closed while constructing resource then destroy it and return an error
|
||||
if p.closed {
|
||||
// If closed or reset while constructing resource then destroy it
|
||||
if p.closed || res.poolResetCount != p.resetCount {
|
||||
p.allResources.remove(res)
|
||||
go p.destructResourceValue(res.value)
|
||||
return ErrClosedPool
|
||||
if p.closed {
|
||||
return ErrClosedPool
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
p.idleResources.Push(res)
|
||||
|
||||
Reference in new issue
Block a user