lib/vmselectapi: move the code for checking the expected client errors into a isExpectedError() function

This commit is contained in:
Aliaksandr Valialkin 2023-07-06 16:37:59 -07:00
parent ed868f47f9
commit 3bc3fb6adf
No known key found for this signature in database
GPG key ID: A72BEC6CD3D0DED1

View file

@ -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