Merge pull request #92005 from tkashem/unexpected-eof

retry on 'unexpected EOF' error
This commit is contained in:
Kubernetes Prow Robot 2020-06-16 19:23:13 -07:00 committed by GitHub
commit b0638ada8c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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)
})
}
}