From ec83a87d683f40a9cdfae248839ba6e67c45d22b Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Thu, 7 May 2026 17:06:23 -0700 Subject: [PATCH] perf(s3/lifecycle): defer pool Put on ShardID hasher defer guarantees the hasher returns to the pool even if h.Write or h.Sum panic, preventing pool leak under unexpected failure modes. --- weed/s3api/s3lifecycle/shard.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/weed/s3api/s3lifecycle/shard.go b/weed/s3api/s3lifecycle/shard.go index 080be9cdf..7aed34715 100644 --- a/weed/s3api/s3lifecycle/shard.go +++ b/weed/s3api/s3lifecycle/shard.go @@ -22,12 +22,12 @@ var shardHashPool = sync.Pool{ // the same shard. Implementation: top 4 bits of sha256(bucket || "/" || key). func ShardID(bucket, key string) int { h := shardHashPool.Get().(hash.Hash) + defer shardHashPool.Put(h) h.Reset() h.Write([]byte(bucket)) h.Write([]byte{'/'}) h.Write([]byte(key)) var buf [sha256.Size]byte sum := h.Sum(buf[:0]) - shardHashPool.Put(h) return int(sum[0] >> 4) }