mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Merge pull request #92005 from tkashem/unexpected-eof
retry on 'unexpected EOF' error
This commit is contained in:
commit
b0638ada8c
@ -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"):
|
||||
|
@ -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)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user