diff --git a/internal/grid/connection.go b/internal/grid/connection.go index 30d35edf2..2203c9580 100644 --- a/internal/grid/connection.go +++ b/internal/grid/connection.go @@ -899,7 +899,6 @@ func (c *Connection) handleMessages(ctx context.Context, conn net.Conn) { } continue } - if int64(cap(dst)) < hdr.Length+1 { dst = make([]byte, 0, hdr.Length+hdr.Length>>3) } @@ -914,6 +913,10 @@ func (c *Connection) handleMessages(ctx context.Context, conn net.Conn) { cancel(ErrDisconnected) return } + if cap(msg) > readBufferSize*8 { + // Don't keep too much memory around. + msg = nil + } var err error msg, err = readDataInto(msg, conn, c.side, ws.OpBinary)