-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.go
52 lines (45 loc) · 885 Bytes
/
util.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
package dlstream
import (
"errors"
"io"
"net"
"syscall"
)
// shouldRetryRequest analyzes a given request error and determines whether its a good idea to retry the request
func shouldRetryRequest(err error) bool {
if err == nil {
return false
}
if errors.Is(err, io.ErrUnexpectedEOF) {
return true
}
var netError net.Error
if errors.As(err, &netError) && netError.Timeout() {
return true
}
var netOpError *net.OpError
if errors.As(err, &netOpError) {
switch netOpError.Op {
case "dial":
return false
case "read":
return true
}
}
var errNo *syscall.Errno
if errors.As(err, &errNo) {
if *errNo == syscall.ECONNREFUSED {
// Connection refused
return true
}
if *errNo == syscall.ECONNRESET {
// Connection reset
return true
}
if *errNo == syscall.ECONNABORTED {
// Connection aborted
return true
}
}
return false
}