mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2025-01-20 15:16:42 +00:00
lib/vmselectapi: move the code for checking the expected client errors into a isExpectedError() function
This commit is contained in:
parent
ed868f47f9
commit
3bc3fb6adf
1 changed files with 20 additions and 11 deletions
|
@ -253,17 +253,7 @@ func (s *Server) processConn(bc *handshake.BufferedConn) error {
|
|||
}
|
||||
for {
|
||||
if err := s.processRequest(ctx); err != nil {
|
||||
if err == io.EOF {
|
||||
// Remote client gracefully closed the connection.
|
||||
return nil
|
||||
}
|
||||
if errors.Is(err, net.ErrClosed) ||
|
||||
strings.Contains(err.Error(), "broken pipe") ||
|
||||
strings.Contains(err.Error(), "connection reset by peer") {
|
||||
// The connection has been interrupted abruptly.
|
||||
// It could happen due to unexpected network glitch or because connection was
|
||||
// interrupted by remote client. In both cases, remote client will notice
|
||||
// connection breach and handle it on its own. No need in mirroring the error here.
|
||||
if isExpectedError(err) {
|
||||
return nil
|
||||
}
|
||||
if errors.Is(err, storage.ErrDeadlineExceeded) {
|
||||
|
@ -277,6 +267,25 @@ func (s *Server) processConn(bc *handshake.BufferedConn) error {
|
|||
}
|
||||
}
|
||||
|
||||
func isExpectedError(err error) bool {
|
||||
if err == io.EOF {
|
||||
// Remote client gracefully closed the connection.
|
||||
return true
|
||||
}
|
||||
if errors.Is(err, net.ErrClosed) {
|
||||
return true
|
||||
}
|
||||
errStr := err.Error()
|
||||
if strings.Contains(errStr, "broken pipe") || strings.Contains(errStr, "connection reset by peer") {
|
||||
// The connection has been interrupted abruptly.
|
||||
// It could happen due to unexpected network glitch or because connection was
|
||||
// interrupted by remote client. In both cases, remote client will notice
|
||||
// connection breach and handle it on its own. No need in mirroring the error here.
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
type vmselectRequestCtx struct {
|
||||
bc *handshake.BufferedConn
|
||||
sizeBuf []byte
|
||||
|
|
Loading…
Reference in a new issue