Skip to content

Commit af72dbd

Browse files
authored
Merge pull request #366 from pohly/buffer-size-limit
buffer: restore dropping of too large buffers
2 parents 1025055 + 2582956 commit af72dbd

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

internal/buffer/buffer.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,17 @@ func GetBuffer() *Buffer {
5555

5656
// PutBuffer returns a buffer to the free list.
5757
func PutBuffer(b *Buffer) {
58+
if b.Len() >= 256 {
59+
// Let big buffers die a natural death, without relying on
60+
// sync.Pool behavior. The documentation implies that items may
61+
// get deallocated while stored there ("If the Pool holds the
62+
// only reference when this [= be removed automatically]
63+
// happens, the item might be deallocated."), but
64+
// https://github.com/golang/go/issues/23199 leans more towards
65+
// having such a size limit.
66+
return
67+
}
68+
5869
buffers.Put(b)
5970
}
6071

0 commit comments

Comments
 (0)