Skip to content

Commit

Permalink
fix: Treat "connection refused" error as a transient network error. (#…
Browse files Browse the repository at this point in the history
…11237)

Signed-off-by: rbushrian <rbushrian@akamai.com>
Co-authored-by: rbushrian <rbushrian@akamai.com>
  • Loading branch information
rbushri and rbushrian authored Jun 20, 2023
1 parent 9229989 commit abc4e8f
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 @@ -86,6 +86,9 @@ func isTransientNetworkErr(err error) bool {
} else if strings.Contains(errorString, "http2: client connection lost") {
// If err is http2 transport ping timeout, retry.
return true
} else if strings.Contains(errorString, "connect: connection refused") {
// If err is connection refused, 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 @@ -44,6 +44,7 @@ var (
connectionTimedoutUErr *url.Error = urlError("connection timed out")
connectionResetUErr *url.Error = urlError("connection reset by peer")
EOFUErr *url.Error = urlError("EOF")
connectionRefusedErr *url.Error = urlError("connect: connection refused")
)

const transientEnvVarKey = "TRANSIENT_ERROR_PATTERN"
Expand Down Expand Up @@ -101,6 +102,9 @@ func TestIsTransientErr(t *testing.T) {
t.Run("ExplicitTransientErr", func(t *testing.T) {
assert.True(t, IsTransientErr(NewErrTransient("")))
})
t.Run("ConnectionRefusedTransientErr", func(t *testing.T) {
assert.True(t, IsTransientErr(connectionRefusedErr))
})
}

func TestIsTransientUErr(t *testing.T) {
Expand Down

0 comments on commit abc4e8f

Please sign in to comment.