Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

transport: limit writer buffer size #251

Merged
merged 1 commit into from
Sep 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

* [ENHANCEMENT] Re-enable TLS 1.3 channel binding during auth using [RFC 9266](https://www.rfc-editor.org/rfc/rfc9266).
* [ENHANCEMENT] hook: include propagated context into execution parameter. [249](https://github.com/ortuman/jackal/pull/249)
* [ENHANCEMENT] transport: limit writer buffer size [#251](https://github.com/ortuman/jackal/pull/251)

## 0.61.0 (2022/06/06)

Expand Down
12 changes: 9 additions & 3 deletions pkg/transport/socket.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,17 @@ import (
"golang.org/x/time/rate"
)

const readBufferSize = 4096
const (
readBufferSize = 4096

maxWriteBufferSize = 256 * 1024
)

var errNoWriteFlush = errors.New("transport: flushing buffer before writing")

var bufWriterPool = sync.Pool{
New: func() interface{} {
return bufio.NewWriter(nil)
return bufio.NewWriterSize(nil, maxWriteBufferSize)
},
}

Expand Down Expand Up @@ -213,6 +217,8 @@ func (s *socketTransport) releaseBuffWriter() {
if s.bw == nil {
return
}
bufWriterPool.Put(s.bw)
if s.bw.Size() <= maxWriteBufferSize {
bufWriterPool.Put(s.bw)
}
s.bw = nil
}