mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2025-01-30 15:22:07 +00:00
lib/handshake: log read/write operation duration on connection errors
This improve debuggability of network errors
This commit is contained in:
parent
c8dde1fd6b
commit
c67a07b469
2 changed files with 15 additions and 3 deletions
|
@ -311,7 +311,7 @@ func (s *Server) processVMInsertConn(bc *handshake.BufferedConn) error {
|
|||
}
|
||||
reqBuf = bytesutil.Resize(reqBuf, int(packetSize))
|
||||
if n, err := io.ReadFull(bc, reqBuf); err != nil {
|
||||
return fmt.Errorf("cannot read packet with size %d: %w; read only %d bytes", packetSize, err, n)
|
||||
return fmt.Errorf("cannot read packet with size %d bytes: %w; read only %d bytes", packetSize, err, n)
|
||||
}
|
||||
// Send `ack` to vminsert that the packet has been received.
|
||||
deadline := time.Now().Add(5 * time.Second)
|
||||
|
|
|
@ -2,8 +2,10 @@ package handshake
|
|||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"time"
|
||||
|
||||
"github.com/VictoriaMetrics/VictoriaMetrics/lib/encoding/zstd"
|
||||
)
|
||||
|
@ -43,14 +45,24 @@ func newBufferedConn(c net.Conn, compressionLevel int, isReadCompressed bool) *B
|
|||
|
||||
// Read reads up to len(p) from bc to p.
|
||||
func (bc *BufferedConn) Read(p []byte) (int, error) {
|
||||
return bc.br.Read(p)
|
||||
startTime := time.Now()
|
||||
n, err := bc.br.Read(p)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("cannot read data in %.3f seconds: %w", time.Since(startTime).Seconds(), err)
|
||||
}
|
||||
return n, err
|
||||
}
|
||||
|
||||
// Write writes p to bc.
|
||||
//
|
||||
// Do not forget to call Flush if needed.
|
||||
func (bc *BufferedConn) Write(p []byte) (int, error) {
|
||||
return bc.bw.Write(p)
|
||||
startTime := time.Now()
|
||||
n, err := bc.bw.Write(p)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("cannot write data in %.3f seconds: %w", time.Since(startTime).Seconds(), err)
|
||||
}
|
||||
return n, err
|
||||
}
|
||||
|
||||
// Close closes bc.
|
||||
|
|
Loading…
Reference in a new issue