Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

retry on 'unexpected EOF' error #92005

Merged
merged 1 commit into from Jun 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions staging/src/k8s.io/apimachinery/pkg/util/net/http.go
Expand Up @@ -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"):
Expand Down
63 changes: 63 additions & 0 deletions staging/src/k8s.io/apimachinery/pkg/util/net/http_test.go
Expand Up @@ -23,6 +23,7 @@ import (
"bytes"
"crypto/tls"
"fmt"
"io"
"io/ioutil"
"net"
"net/http"
Expand Down Expand Up @@ -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)
})
}
}