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
This commit is contained in:
Aliaksandr Valialkin 2019-09-11 14:11:37 +03:00
parent 2f4c950fe9
commit b101064f8b
3 changed files with 8 additions and 8 deletions

View file

@ -1296,8 +1296,8 @@ func readBytes(buf []byte, bc *handshake.BufferedConn, maxDataSize int) ([]byte,
if dataSize == 0 { if dataSize == 0 {
return buf, nil return buf, nil
} }
if _, err := io.ReadFull(bc, buf); err != nil { if n, err := io.ReadFull(bc, buf); err != nil {
return buf, fmt.Errorf("cannot read data with size %d: %s", dataSize, err) return buf, fmt.Errorf("cannot read data with size %d: %s; read only %d bytes", dataSize, err, n)
} }
return buf, nil return buf, nil
} }

View file

@ -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) return fmt.Errorf("too big packet size: %d; shouldn't exceed %d", packetSize, consts.MaxInsertPacketSize)
} }
buf = bytesutil.Resize(buf, int(packetSize)) buf = bytesutil.Resize(buf, int(packetSize))
if _, err := io.ReadFull(r, buf); err != nil { if n, err := io.ReadFull(r, buf); err != nil {
return fmt.Errorf("cannot read packet with size %d: %s", packetSize, err) return fmt.Errorf("cannot read packet with size %d: %s; read only %d bytes", packetSize, err, n)
} }
vminsertPacketsRead.Inc() vminsertPacketsRead.Inc()
@ -386,8 +386,8 @@ func (ctx *vmselectRequestCtx) readDataBufBytes(maxDataSize int) error {
if dataSize == 0 { if dataSize == 0 {
return nil return nil
} }
if _, err := io.ReadFull(ctx.bc, ctx.dataBuf); err != nil { if n, err := io.ReadFull(ctx.bc, ctx.dataBuf); err != nil {
return fmt.Errorf("cannot read data with size %d: %s", dataSize, err) return fmt.Errorf("cannot read data with size %d: %s; read only %d bytes", dataSize, err, n)
} }
return nil return nil
} }

View file

@ -158,8 +158,8 @@ func readData(c net.Conn, dataLen int) ([]byte, error) {
return nil, fmt.Errorf("cannot set read deadline: %s", err) return nil, fmt.Errorf("cannot set read deadline: %s", err)
} }
data := make([]byte, dataLen) data := make([]byte, dataLen)
if _, err := io.ReadFull(c, data); err != nil { if n, err := io.ReadFull(c, data); err != nil {
return nil, fmt.Errorf("cannot read message with size %d: %s", dataLen, err) 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 { if err := c.SetReadDeadline(zeroTime); err != nil {
return nil, fmt.Errorf("cannot reset read deadline: %s", err) return nil, fmt.Errorf("cannot reset read deadline: %s", err)