From 3aa8a8586168ca4f33f80f48cacc78544d350b66 Mon Sep 17 00:00:00 2001 From: Alexey Kiselev Date: Fri, 13 Dec 2024 12:02:33 +0400 Subject: [PATCH] Better read error handling. Co-authored-by: Nikolay Eskov --- pkg/networking/session.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pkg/networking/session.go b/pkg/networking/session.go index aea9209f9..9d1b1c73f 100644 --- a/pkg/networking/session.go +++ b/pkg/networking/session.go @@ -298,11 +298,14 @@ func (s *Session) readHandshake() error { func (s *Session) readMessage(hdr Header) error { // Read the header if _, err := hdr.ReadFrom(s.bufRead); err != nil { - if errors.Is(err, io.EOF) || strings.Contains(err.Error(), "closed") || - strings.Contains(err.Error(), "reset by peer") || - strings.Contains(err.Error(), "broken pipe") { // In Docker network built on top of pipe, we get this error on close. + if errors.Is(err, io.EOF) { return ErrConnectionClosedOnRead } + if errMsg := err.Error(); strings.Contains(errMsg, "closed") || + strings.Contains(errMsg, "reset by peer") || + strings.Contains(errMsg, "broken pipe") { // In Docker network built on top of pipe, we get this error on close. + return errors.Join(ErrConnectionClosedOnRead, err) // Wrap the error with ErrConnectionClosedOnRead. + } s.logger.Error("Failed to read header", "error", err) return err }