Skip to content

Commit 6d50805

Browse files
authored
Fix race condition in pool.BucketedBytes (#4095)
Signed-off-by: Marco Pracucci <[email protected]>
1 parent 393a471 commit 6d50805

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

pkg/pool/pool.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,13 @@ func (p *BucketedBytes) Put(b *[]byte) {
112112
continue
113113
}
114114
*b = (*b)[:0]
115-
p.mtx.Lock()
116-
defer p.mtx.Unlock()
117115
p.buckets[i].Put(b)
118116
break
119117
}
120118

119+
p.mtx.Lock()
120+
defer p.mtx.Unlock()
121+
121122
// We could assume here that our users will not make the slices larger
122123
// but lets be on the safe side to avoid an underflow of p.usedTotal.
123124
sz := uint64(cap(*b))

0 commit comments

Comments
 (0)