From 7fe653c350f32f257912e4d93f71957b8305f766 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Fri, 10 Jun 2016 13:48:41 +0100 Subject: [PATCH] Unwrap errors properly for patform specific connection retry code. Include more possible errors for Windows. For #442 --- fs/closed_conn_win.go | 11 +++++++++-- fs/error.go | 13 +++++++++---- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/fs/closed_conn_win.go b/fs/closed_conn_win.go index 488d22f7a..7bed21455 100644 --- a/fs/closed_conn_win.go +++ b/fs/closed_conn_win.go @@ -16,8 +16,15 @@ func isClosedConnErrorPlatform(err error) bool { if oe, ok := err.(*net.OpError); ok { if se, ok := oe.Err.(*os.SyscallError); ok { if errno, ok := se.Err.(syscall.Errno); ok { - const WSAECONNABORTED syscall.Errno = 10053 - if errno == syscall.WSAECONNRESET || errno == WSAECONNABORTED { + const ( + WSAECONNABORTED syscall.Errno = 10053 + WSAHOST_NOT_FOUND syscall.Errno = 11001 + WSATRY_AGAIN syscall.Errno = 11002 + WSAENETRESET syscall.Errno = 10052 + WSAETIMEDOUT syscall.Errno = 10060 + ) + switch errno { + case syscall.WSAECONNRESET, WSAECONNABORTED, WSAHOST_NOT_FOUND, WSATRY_AGAIN, WSAENETRESET, WSAETIMEDOUT: return true } } diff --git a/fs/error.go b/fs/error.go index 97c9e2ee3..6567aae9e 100644 --- a/fs/error.go +++ b/fs/error.go @@ -8,6 +8,8 @@ import ( "net/http" "net/url" "strings" + + "github.com/pkg/errors" ) // Retry is an optional interface for error as to whether the @@ -95,16 +97,19 @@ func ShouldRetry(err error) bool { return false } - // Look for premature closing of connection - if err == io.EOF || err == io.ErrUnexpectedEOF || isClosedConnError(err) { - return true - } + // Find root cause if available + err = errors.Cause(err) // Unwrap url.Error if urlErr, ok := err.(*url.Error); ok { err = urlErr.Err } + // Look for premature closing of connection + if err == io.EOF || err == io.ErrUnexpectedEOF || isClosedConnError(err) { + return true + } + // Check for net error Timeout() if x, ok := err.(interface { Timeout() bool