Skip to content

Commit b0638ad

Browse files
authored
Merge pull request kubernetes#92005 from tkashem/unexpected-eof
retry on 'unexpected EOF' error
2 parents 7e073db + e73fa4a commit b0638ad

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

staging/src/k8s.io/apimachinery/pkg/util/net/http.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ func IsProbableEOF(err error) bool {
8383
switch {
8484
case err == io.EOF:
8585
return true
86+
case err == io.ErrUnexpectedEOF:
87+
return true
8688
case msg == "http: can't write HTTP request on broken connection":
8789
return true
8890
case strings.Contains(msg, "http2: server sent GOAWAY and closed the connection"):

staging/src/k8s.io/apimachinery/pkg/util/net/http_test.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"bytes"
2424
"crypto/tls"
2525
"fmt"
26+
"io"
2627
"io/ioutil"
2728
"net"
2829
"net/http"
@@ -1008,3 +1009,65 @@ func TestParseWarningHeaders(t *testing.T) {
10081009
})
10091010
}
10101011
}
1012+
1013+
func TestIsProbableEOF(t *testing.T) {
1014+
tests := []struct {
1015+
name string
1016+
err error
1017+
expected bool
1018+
}{
1019+
{
1020+
name: "with no error",
1021+
expected: false,
1022+
},
1023+
{
1024+
name: "with EOF error",
1025+
err: io.EOF,
1026+
expected: true,
1027+
},
1028+
{
1029+
name: "with unexpected EOF error",
1030+
err: io.ErrUnexpectedEOF,
1031+
expected: true,
1032+
},
1033+
{
1034+
name: "with broken connection error",
1035+
err: fmt.Errorf("http: can't write HTTP request on broken connection"),
1036+
expected: true,
1037+
},
1038+
{
1039+
name: "with server sent GOAWAY error",
1040+
err: fmt.Errorf("error foo - http2: server sent GOAWAY and closed the connection - error bar"),
1041+
expected: true,
1042+
},
1043+
{
1044+
name: "with connection reset by peer error",
1045+
err: fmt.Errorf("error foo - connection reset by peer - error bar"),
1046+
expected: true,
1047+
},
1048+
{
1049+
name: "with use of closed network connection error",
1050+
err: fmt.Errorf("error foo - Use of closed network connection - error bar"),
1051+
expected: true,
1052+
},
1053+
{
1054+
name: "with url error",
1055+
err: &url.Error{
1056+
Err: io.ErrUnexpectedEOF,
1057+
},
1058+
expected: true,
1059+
},
1060+
{
1061+
name: "with unrecognized error",
1062+
err: fmt.Errorf("error foo"),
1063+
expected: false,
1064+
},
1065+
}
1066+
1067+
for _, test := range tests {
1068+
t.Run(test.name, func(t *testing.T) {
1069+
actual := IsProbableEOF(test.err)
1070+
assert.Equal(t, test.expected, actual)
1071+
})
1072+
}
1073+
}

0 commit comments

Comments
 (0)