Skip to content

Commit

Permalink
WebSocket: Ensure full writes to compressor (#6091)
Browse files Browse the repository at this point in the history
The `cp.Write()` call may have been partial and we would not have
noticed.

Signed-off-by: Neil Twigg <neil@nats.io>
  • Loading branch information
derekcollison authored Nov 14, 2024
2 parents 36e94b0 + 0b29dea commit 2b8d891
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 2b8d891

Please sign in to comment.