rclone/fs/closed_conn.go
Nick Craig-Wood 798502b204 fs: add more errors to be considered temporary errors
This makes a framework for adding temporary errors identified by
syscall number or by error string.

Fixes #1660
2017-09-14 18:01:43 +01:00

46 lines
1 KiB
Go

// +build !plan9
package fs
import (
"net"
"os"
"syscall"
)
// closedConnErrors indicate a connection is closed or broken and
// should be retried
//
// These are added to in closed_conn_win.go
var closedConnErrors = []syscall.Errno{
syscall.EPIPE,
syscall.ETIMEDOUT,
syscall.ECONNREFUSED,
syscall.EHOSTDOWN,
syscall.EHOSTUNREACH,
syscall.ECONNABORTED,
syscall.EAGAIN,
syscall.EWOULDBLOCK,
syscall.ECONNRESET,
}
// isClosedConnErrorPlatform reports whether err is an error from use
// of a closed network connection using platform specific error codes.
func isClosedConnErrorPlatform(err error) bool {
// now check whether err is an error from use of a closed
// network connection using platform specific error codes.
//
// Code adapted from net/http
if oe, ok := err.(*net.OpError); ok {
if se, ok := oe.Err.(*os.SyscallError); ok {
if errno, ok := se.Err.(syscall.Errno); ok {
for _, retriableErrno := range closedConnErrors {
if errno == retriableErrno {
return true
}
}
}
}
}
return false
}