|
@@ -512,8 +512,9 @@ func (c *rawConnection) readMessageAfterHeader(hdr *bep.Header, fourByteBuf []by
|
|
// Then comes the message
|
|
// Then comes the message
|
|
|
|
|
|
buf := BufferPool.Get(int(msgLen))
|
|
buf := BufferPool.Get(int(msgLen))
|
|
|
|
+ defer BufferPool.Put(buf)
|
|
|
|
+
|
|
if _, err := io.ReadFull(c.cr, buf); err != nil {
|
|
if _, err := io.ReadFull(c.cr, buf); err != nil {
|
|
- BufferPool.Put(buf)
|
|
|
|
return nil, fmt.Errorf("reading message: %w", err)
|
|
return nil, fmt.Errorf("reading message: %w", err)
|
|
}
|
|
}
|
|
|
|
|
|
@@ -525,7 +526,6 @@ func (c *rawConnection) readMessageAfterHeader(hdr *bep.Header, fourByteBuf []by
|
|
|
|
|
|
case bep.MessageCompression_MESSAGE_COMPRESSION_LZ4:
|
|
case bep.MessageCompression_MESSAGE_COMPRESSION_LZ4:
|
|
decomp, err := lz4Decompress(buf)
|
|
decomp, err := lz4Decompress(buf)
|
|
- BufferPool.Put(buf)
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
return nil, fmt.Errorf("decompressing message: %w", err)
|
|
return nil, fmt.Errorf("decompressing message: %w", err)
|
|
}
|
|
}
|
|
@@ -541,14 +541,11 @@ func (c *rawConnection) readMessageAfterHeader(hdr *bep.Header, fourByteBuf []by
|
|
|
|
|
|
msg, err := newMessage(hdr.Type)
|
|
msg, err := newMessage(hdr.Type)
|
|
if err != nil {
|
|
if err != nil {
|
|
- BufferPool.Put(buf)
|
|
|
|
return nil, err
|
|
return nil, err
|
|
}
|
|
}
|
|
if err := proto.Unmarshal(buf, msg); err != nil {
|
|
if err := proto.Unmarshal(buf, msg); err != nil {
|
|
- BufferPool.Put(buf)
|
|
|
|
return nil, fmt.Errorf("unmarshalling message: %w", err)
|
|
return nil, fmt.Errorf("unmarshalling message: %w", err)
|
|
}
|
|
}
|
|
- BufferPool.Put(buf)
|
|
|
|
|
|
|
|
return msg, nil
|
|
return msg, nil
|
|
}
|
|
}
|
|
@@ -567,16 +564,16 @@ func (c *rawConnection) readHeader(fourByteBuf []byte) (*bep.Header, error) {
|
|
// Then comes the header
|
|
// Then comes the header
|
|
|
|
|
|
buf := BufferPool.Get(int(hdrLen))
|
|
buf := BufferPool.Get(int(hdrLen))
|
|
|
|
+ defer BufferPool.Put(buf)
|
|
|
|
+
|
|
if _, err := io.ReadFull(c.cr, buf); err != nil {
|
|
if _, err := io.ReadFull(c.cr, buf); err != nil {
|
|
- BufferPool.Put(buf)
|
|
|
|
return nil, fmt.Errorf("reading header: %w", err)
|
|
return nil, fmt.Errorf("reading header: %w", err)
|
|
}
|
|
}
|
|
|
|
|
|
var hdr bep.Header
|
|
var hdr bep.Header
|
|
err := proto.Unmarshal(buf, &hdr)
|
|
err := proto.Unmarshal(buf, &hdr)
|
|
- BufferPool.Put(buf)
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
- return nil, fmt.Errorf("unmarshalling header: %w %x", err, buf)
|
|
|
|
|
|
+ return nil, fmt.Errorf("unmarshalling header: %w", err)
|
|
}
|
|
}
|
|
|
|
|
|
metricDeviceRecvDecompressedBytes.WithLabelValues(c.idString).Add(float64(2 + len(buf)))
|
|
metricDeviceRecvDecompressedBytes.WithLabelValues(c.idString).Add(float64(2 + len(buf)))
|