From b101064f8b88cdfe719326430e40f43414af9990 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Wed, 11 Sep 2019 14:11:37 +0300 Subject: [PATCH] all: report the number of bytes read on io.ReadFull error This should simplify error investigation similar to https://github.com/VictoriaMetrics/VictoriaMetrics/issues/175 --- app/vmselect/netstorage/netstorage.go | 4 ++-- app/vmstorage/transport/server.go | 8 ++++---- lib/handshake/handshake.go | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/vmselect/netstorage/netstorage.go b/app/vmselect/netstorage/netstorage.go index 5f61882c3..ff3d53925 100644 --- a/app/vmselect/netstorage/netstorage.go +++ b/app/vmselect/netstorage/netstorage.go @@ -1296,8 +1296,8 @@ func readBytes(buf []byte, bc *handshake.BufferedConn, maxDataSize int) ([]byte, if dataSize == 0 { return buf, nil } - if _, err := io.ReadFull(bc, buf); err != nil { - return buf, fmt.Errorf("cannot read data with size %d: %s", dataSize, err) + if n, err := io.ReadFull(bc, buf); err != nil { + return buf, fmt.Errorf("cannot read data with size %d: %s; read only %d bytes", dataSize, err, n) } return buf, nil } diff --git a/app/vmstorage/transport/server.go b/app/vmstorage/transport/server.go index 2fcdcdea7..b09e07d0c 100644 --- a/app/vmstorage/transport/server.go +++ b/app/vmstorage/transport/server.go @@ -291,8 +291,8 @@ func (s *Server) processVMInsertConn(r io.Reader) error { return fmt.Errorf("too big packet size: %d; shouldn't exceed %d", packetSize, consts.MaxInsertPacketSize) } buf = bytesutil.Resize(buf, int(packetSize)) - if _, err := io.ReadFull(r, buf); err != nil { - return fmt.Errorf("cannot read packet with size %d: %s", packetSize, err) + if n, err := io.ReadFull(r, buf); err != nil { + return fmt.Errorf("cannot read packet with size %d: %s; read only %d bytes", packetSize, err, n) } vminsertPacketsRead.Inc() @@ -386,8 +386,8 @@ func (ctx *vmselectRequestCtx) readDataBufBytes(maxDataSize int) error { if dataSize == 0 { return nil } - if _, err := io.ReadFull(ctx.bc, ctx.dataBuf); err != nil { - return fmt.Errorf("cannot read data with size %d: %s", dataSize, err) + if n, err := io.ReadFull(ctx.bc, ctx.dataBuf); err != nil { + return fmt.Errorf("cannot read data with size %d: %s; read only %d bytes", dataSize, err, n) } return nil } diff --git a/lib/handshake/handshake.go b/lib/handshake/handshake.go index 0a71bdd1a..814611985 100644 --- a/lib/handshake/handshake.go +++ b/lib/handshake/handshake.go @@ -158,8 +158,8 @@ func readData(c net.Conn, dataLen int) ([]byte, error) { return nil, fmt.Errorf("cannot set read deadline: %s", err) } data := make([]byte, dataLen) - if _, err := io.ReadFull(c, data); err != nil { - return nil, fmt.Errorf("cannot read message with size %d: %s", dataLen, err) + if n, err := io.ReadFull(c, data); err != nil { + return nil, fmt.Errorf("cannot read message with size %d: %s; read only %d bytes", dataLen, err, n) } if err := c.SetReadDeadline(zeroTime); err != nil { return nil, fmt.Errorf("cannot reset read deadline: %s", err)