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

Commit

Permalink
transport: limit writer buffer size (#251)
Browse files Browse the repository at this point in the history
Signed-off-by: Miguel 脕ngel Ortu帽o <ortuman@gmail.com>
  • Loading branch information
ortuman committed Sep 13, 2022
1 parent 1ab7b13 commit 7059043
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
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
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
}

0 comments on commit 7059043

Please sign in to comment.