Skip to content

Commit

Permalink
WebSocket: Ensure full writes to compressor
Browse files Browse the repository at this point in the history
Signed-off-by: Neil Twigg <neil@nats.io>
  • Loading branch information
neilalexander committed Nov 14, 2024
1 parent da1dcda commit 0b29dea
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion server/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -1367,7 +1367,19 @@ func (c *client) wsCollapsePtoNB() (net.Buffers, int64) {
}
var csz int
for _, b := range nb {
cp.Write(b)
for len(b) > 0 {
n, err := cp.Write(b)
if err != nil {
if err == io.EOF {
break
}
c.Errorf("Error during compression: %v", err)
c.markConnAsClosed(WriteError)
nbPoolPut(b)
return nil, 0
}
b = b[n:]
}
nbPoolPut(b) // No longer needed as contents written to compressor.
}
if err := cp.Flush(); err != nil {
Expand Down

0 comments on commit 0b29dea

Please sign in to comment.