Skip to content

Commit

Permalink
fix: Treat 'connection reset by peer' as a transient network error. F…
Browse files Browse the repository at this point in the history
…ixes #9013 (#9017)

Treat 'connection reset by peer' as a transient network error, Fixes #9013

Signed-off-by: Mike Tougeron <[email protected]>
  • Loading branch information
mtougeron authored Jun 21, 2022
1 parent cd43d01 commit 6228748
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions util/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ func isTransientNetworkErr(err error) bool {
} else if strings.Contains(errorString, "connection timed out") {
// If err is a net.Dial timeout, retry.
return true
} else if strings.Contains(errorString, "connection reset by peer") {
// If err is a ECONNRESET, retry.
return true
}

return false
Expand Down
4 changes: 4 additions & 0 deletions util/errors/errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var (
tlsHandshakeTimeoutErr net.Error = netError("net/http: TLS handshake timeout")
ioTimeoutErr net.Error = netError("i/o timeout")
connectionTimedout net.Error = netError("connection timed out")
connectionReset net.Error = netError("connection reset by peer")
transientErr net.Error = netError("this error is transient")
transientExitErr = exec.ExitError{
ProcessState: &os.ProcessState{},
Expand Down Expand Up @@ -69,6 +70,9 @@ func TestIsTransientErr(t *testing.T) {
t.Run("ConnectionTimeout", func(t *testing.T) {
assert.True(t, IsTransientErr(connectionTimedout))
})
t.Run("ConnectionReset", func(t *testing.T) {
assert.True(t, IsTransientErr(connectionReset))
})
t.Run("TransientErrorPattern", func(t *testing.T) {
_ = os.Setenv(transientEnvVarKey, "this error is transient")
assert.True(t, IsTransientErr(transientErr))
Expand Down

0 comments on commit 6228748

Please sign in to comment.