-
Notifications
You must be signed in to change notification settings - Fork 301
/
retryable.go
56 lines (47 loc) · 1.06 KB
/
retryable.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package api
import (
"io"
"net"
"net/url"
"strings"
"syscall"
)
var retrableErrorSuffixes = []string{
syscall.ECONNREFUSED.Error(),
syscall.ECONNRESET.Error(),
syscall.ETIMEDOUT.Error(),
"no such host",
"remote error: handshake failure",
io.ErrUnexpectedEOF.Error(),
io.EOF.Error(),
}
// Looks at a bunch of connection related errors, and returns true if the error
// matches one of them.
func IsRetryableError(err error) bool {
if neterr, ok := err.(net.Error); ok {
if neterr.Temporary() {
return true
}
}
if neterr, ok := err.(net.Error); ok && neterr.Timeout() {
return true
}
if urlerr, ok := err.(*url.Error); ok {
if strings.Contains(urlerr.Error(), "use of closed network connection") {
return true
}
if neturlerr, ok := urlerr.Err.(net.Error); ok && neturlerr.Timeout() {
return true
}
}
if strings.Contains(err.Error(), "request canceled while waiting for connection") {
return true
}
s := err.Error()
for _, suffix := range retrableErrorSuffixes {
if strings.HasSuffix(s, suffix) {
return true
}
}
return false
}