Skip to content

Commit

Permalink
Better read error handling.
Browse files Browse the repository at this point in the history
Co-authored-by: Nikolay Eskov <[email protected]>
  • Loading branch information
alexeykiselev and nickeskov authored Dec 13, 2024
1 parent c2ad101 commit 3aa8a85
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions pkg/networking/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 3aa8a85

Please sign in to comment.