retry on 'unexpected EOF' error

'unexpected EOF' is usually a transient error. client-go request
uses IsProbableEOF to determine whether it is going to retry a
failed request.
This commit is contained in:
Abu Kashem 2020-06-10 16:20:37 -04:00
parent 9b53b9306e
commit e73fa4a186
No known key found for this signature in database
GPG Key ID: 76146D1A14E658ED
2 changed files with 65 additions and 0 deletions

View File

@ -83,6 +83,8 @@ func IsProbableEOF(err error) bool {
switch {
case err == io.EOF:
return true
case err == io.ErrUnexpectedEOF:
return true
case msg == "http: can't write HTTP request on broken connection":
return true
case strings.Contains(msg, "http2: server sent GOAWAY and closed the connection"):

View File

@ -23,6 +23,7 @@ import (
"bytes"
"crypto/tls"
"fmt"
"io"
"io/ioutil"
"net"
"net/http"
@ -1008,3 +1009,65 @@ func TestParseWarningHeaders(t *testing.T) {
})
}
}
func TestIsProbableEOF(t *testing.T) {
tests := []struct {
name string
err error
expected bool
}{
{
name: "with no error",
expected: false,
},
{
name: "with EOF error",
err: io.EOF,
expected: true,
},
{
name: "with unexpected EOF error",
err: io.ErrUnexpectedEOF,
expected: true,
},
{
name: "with broken connection error",
err: fmt.Errorf("http: can't write HTTP request on broken connection"),
expected: true,
},
{
name: "with server sent GOAWAY error",
err: fmt.Errorf("error foo - http2: server sent GOAWAY and closed the connection - error bar"),
expected: true,
},
{
name: "with connection reset by peer error",
err: fmt.Errorf("error foo - connection reset by peer - error bar"),
expected: true,
},
{
name: "with use of closed network connection error",
err: fmt.Errorf("error foo - Use of closed network connection - error bar"),
expected: true,
},
{
name: "with url error",
err: &url.Error{
Err: io.ErrUnexpectedEOF,
},
expected: true,
},
{
name: "with unrecognized error",
err: fmt.Errorf("error foo"),
expected: false,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
actual := IsProbableEOF(test.err)
assert.Equal(t, test.expected, actual)
})
}
}