Skip to content

Commit

Permalink
martian: refactor isCloseable
Browse files Browse the repository at this point in the history
Move errClose checking and other error checking before error casting and string searches.
This improves both readability and performance as handling errClose is a common case.
  • Loading branch information
mmatczuk committed Oct 17, 2023
1 parent 2dece1d commit 6da7936
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions internal/martian/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,15 @@ func isClosedConnError(err error) bool {

// isCloseable reports whether err is an error that indicates the client connection should be closed.
func isCloseable(err error) bool {
var neterr net.Error
if ok := errors.As(err, &neterr); ok && neterr.Timeout() {
if errors.Is(err, errClose) ||
errors.Is(err, io.EOF) ||
errors.Is(err, io.ErrUnexpectedEOF) ||
errors.Is(err, io.ErrClosedPipe) {
return true
}

if errors.Is(err, io.EOF) ||
errors.Is(err, io.ErrClosedPipe) ||
errors.Is(err, errClose) {
var neterr net.Error
if ok := errors.As(err, &neterr); ok && neterr.Timeout() {
return true
}

Expand Down

0 comments on commit 6da7936

Please sign in to comment.