diff --git a/router/handler_ctrl/route.go b/router/handler_ctrl/route.go index ce43feee3..59061268f 100644 --- a/router/handler_ctrl/route.go +++ b/router/handler_ctrl/route.go @@ -18,6 +18,7 @@ package handler_ctrl import ( "github.com/openziti/ziti/router/env" + "net" "syscall" "time" @@ -178,7 +179,7 @@ func (rh *routeHandler) connectEgress(msg *channel.Message, attempt int, ch chan switch { case errors.Is(err, syscall.ECONNREFUSED): errCode = ctrl_msg.ErrorTypeConnectionRefused - case errors.Is(err, syscall.ETIMEDOUT): + case isNetworkTimeout(err) || errors.Is(err, syscall.ETIMEDOUT): errCode = ctrl_msg.ErrorTypeDialTimedOut case errors.As(err, &xgress.MisconfiguredTerminatorError{}): errCode = ctrl_msg.ErrorTypeMisconfiguredTerminator @@ -200,6 +201,11 @@ func (rh *routeHandler) connectEgress(msg *channel.Message, attempt int, ch chan } } +func isNetworkTimeout(err error) bool { + var netErr net.Error + return errors.As(err, &netErr) +} + func newDialParams(ctrlId string, route *ctrl_pb.Route, bindHandler xgress.BindHandler, logContext logcontext.Context, deadline time.Time) *dialParams { return &dialParams{ ctrlId: ctrlId, diff --git a/router/handler_ctrl/timeout_check_test.go b/router/handler_ctrl/timeout_check_test.go new file mode 100644 index 000000000..dd1b9d9f1 --- /dev/null +++ b/router/handler_ctrl/timeout_check_test.go @@ -0,0 +1,30 @@ +package handler_ctrl + +import ( + "fmt" + "github.com/stretchr/testify/assert" + "testing" +) + +type testTimeoutErr struct{} + +func (t testTimeoutErr) Error() string { + return "test" +} + +func (t testTimeoutErr) Timeout() bool { + return true +} + +func (t testTimeoutErr) Temporary() bool { + return true +} + +func Test_TimeoutCheck(t *testing.T) { + err := testTimeoutErr{} + req := assert.New(t) + req.True(isNetworkTimeout(err)) + + wrapped := fmt.Errorf("there was an error (%w)", err) + req.True(isNetworkTimeout(wrapped)) +}