Skip to content

Commit

Permalink
fix(bytesBuffer): limit all bytes buffer to 256k
Browse files Browse the repository at this point in the history
  • Loading branch information
paragor committed Sep 8, 2024
1 parent 2aab161 commit eeff934
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}
}
3 changes: 3 additions & 0 deletions pkg/cachebehavior/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/upstream/upstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}
}
Expand Down

0 comments on commit eeff934

Please sign in to comment.