From eeff9344205fd8dc4aef774138771fe40b071165 Mon Sep 17 00:00:00 2001 From: novikov Date: Mon, 9 Sep 2024 03:59:45 +0700 Subject: [PATCH] fix(bytesBuffer): limit all bytes buffer to 256k --- pkg/cache/cache.go | 3 +++ pkg/cachebehavior/cache.go | 3 +++ pkg/upstream/upstream.go | 3 +++ 3 files changed, 9 insertions(+) diff --git a/pkg/cache/cache.go b/pkg/cache/cache.go index 1f5f075..3b6d938 100644 --- a/pkg/cache/cache.go +++ b/pkg/cache/cache.go @@ -43,6 +43,9 @@ var bufferPool = sync.Pool{ func getBytesBuffer() ([]byte, func()) { responseBytesBuffer := bufferPool.Get().([]byte)[:0] return responseBytesBuffer, func() { + if cap(responseBytesBuffer) > 256*1024 { + return + } bufferPool.Put(responseBytesBuffer[:0]) } } diff --git a/pkg/cachebehavior/cache.go b/pkg/cachebehavior/cache.go index c92d90a..27495f6 100644 --- a/pkg/cachebehavior/cache.go +++ b/pkg/cachebehavior/cache.go @@ -219,6 +219,9 @@ var bufferPool = sync.Pool{ func getBytesBuffer() ([]byte, func()) { responseBytesBuffer := bufferPool.Get().([]byte)[:0] return responseBytesBuffer, func() { + if cap(responseBytesBuffer) > 256*1024 { + return + } bufferPool.Put(responseBytesBuffer[:0]) } } diff --git a/pkg/upstream/upstream.go b/pkg/upstream/upstream.go index ee8b124..01d6d4b 100644 --- a/pkg/upstream/upstream.go +++ b/pkg/upstream/upstream.go @@ -118,6 +118,9 @@ var bufferPool = sync.Pool{ func getBytesBuffer() ([]byte, func()) { responseBytesBuffer := bufferPool.Get().([]byte)[:0] return responseBytesBuffer, func() { + if cap(responseBytesBuffer) > 256*1024 { + return + } bufferPool.Put(responseBytesBuffer[:0]) } }