Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMPROVED] Memory growth on compressed websocket connections. #4620

Merged
merged 1 commit into from Oct 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 3 additions & 10 deletions server/websocket.go
Expand Up @@ -115,7 +115,6 @@ type websocket struct {
nocompfrag bool // No fragment for compressed frames
maskread bool
maskwrite bool
compressor *flate.Writer
cookieJwt string
clientIP string
}
Expand Down Expand Up @@ -1295,15 +1294,8 @@ func (c *client) wsCollapsePtoNB() (net.Buffers, int64) {
if mfs > 0 && c.ws.nocompfrag {
mfs = 0
}
buf := &bytes.Buffer{}

cp := c.ws.compressor
if cp == nil {
c.ws.compressor, _ = flate.NewWriter(buf, flate.BestSpeed)
cp = c.ws.compressor
} else {
cp.Reset(buf)
}
buf := bytes.NewBuffer(nbPoolGet(usz))
cp, _ := flate.NewWriter(buf, flate.BestSpeed)
var csz int
for _, b := range nb {
cp.Write(b)
Expand Down Expand Up @@ -1352,6 +1344,7 @@ func (c *client) wsCollapsePtoNB() (net.Buffers, int64) {
}
csz = len(h) + ol
}
nbPoolPut(b) // No longer needed as we copied from above.
// Add to pb the compressed data size (including headers), but
// remove the original uncompressed data size that was added
// during the queueing.
Expand Down