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.
This commit is contained in:
Chris Lu
2026-05-07 17:08:50 -07:00
parent 3a192c6c57
commit ec83a87d68
+1 -1
View File
@@ -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)
}