diff --git a/client/service.go b/client/service.go index 2b1b38aa68059dc0555343b6511583719499eabe..56b70db84e60d1bfc4b735a631e4ae750b363dbe 100644 --- a/client/service.go +++ b/client/service.go @@ -17,6 +17,7 @@ package client import ( "context" "crypto/tls" + "errors" "fmt" "io/ioutil" "net" @@ -177,9 +178,16 @@ func (svr *Service) keepControllerWorking() { if err != nil { xl.Warn("reconnect to server error: %v", err) time.Sleep(delayTime) - delayTime = delayTime * 2 - if delayTime > maxDelayTime { - delayTime = maxDelayTime + + opErr := &net.OpError{} + // quick retry for dial error + if errors.As(err, &opErr) && opErr.Op == "dial" { + delayTime = 2 * time.Second + } else { + delayTime = delayTime * 2 + if delayTime > maxDelayTime { + delayTime = maxDelayTime + } } continue } diff --git a/pkg/config/visitor.go b/pkg/config/visitor.go index f3552b327eb12b69ee02985204273b01c46f652a..11959ecaed1c2c1a87cc2429aea3faa88a6797b1 100644 --- a/pkg/config/visitor.go +++ b/pkg/config/visitor.go @@ -23,7 +23,6 @@ import ( "gopkg.in/ini.v1" ) - // Visitor var ( visitorConfTypeMap = map[string]reflect.Type{ @@ -64,7 +63,6 @@ type XTCPVisitorConf struct { BaseVisitorConf `ini:",extends" json:"inline"` } - // DefaultVisitorConf creates a empty VisitorConf object by visitorType. // If visitorType doesn't exist, return nil. func DefaultVisitorConf(visitorType string) VisitorConf { diff --git a/pkg/config/visitor_test.go b/pkg/config/visitor_test.go index 98b2f09786feac9bc2f70d9a972ef381c0c6e24b..ce200ed049bce1f81fa73a0e9bb2a6ff63980cd5 100644 --- a/pkg/config/visitor_test.go +++ b/pkg/config/visitor_test.go @@ -19,8 +19,8 @@ import ( "github.com/fatedier/frp/pkg/consts" - "gopkg.in/ini.v1" "github.com/stretchr/testify/assert" + "gopkg.in/ini.v1" ) const testVisitorPrefix = "test." diff --git a/tests/ci/cmd_test.go b/tests/ci/cmd_test.go index 8a0b4775161e939a5ac0a6c7ae9b022bce07580e..4a98c446ccbf129fe5c94ccff92b714151de4ed4 100644 --- a/tests/ci/cmd_test.go +++ b/tests/ci/cmd_test.go @@ -19,7 +19,7 @@ func TestCmdTCP(t *testing.T) { if assert.NoError(err) { defer s.Stop() } - time.Sleep(200 * time.Millisecond) + time.Sleep(500 * time.Millisecond) c := util.NewProcess(consts.FRPC_BIN_PATH, []string{"tcp", "-s", "127.0.0.1:20000", "-t", "123", "-u", "test", "-l", "10701", "-r", "20801", "-n", "tcp_test"}) @@ -43,7 +43,7 @@ func TestCmdUDP(t *testing.T) { if assert.NoError(err) { defer s.Stop() } - time.Sleep(200 * time.Millisecond) + time.Sleep(500 * time.Millisecond) c := util.NewProcess(consts.FRPC_BIN_PATH, []string{"udp", "-s", "127.0.0.1:20000", "-t", "123", "-u", "test", "-l", "10702", "-r", "20802", "-n", "udp_test"}) @@ -67,7 +67,7 @@ func TestCmdHTTP(t *testing.T) { if assert.NoError(err) { defer s.Stop() } - time.Sleep(200 * time.Millisecond) + time.Sleep(500 * time.Millisecond) c := util.NewProcess(consts.FRPC_BIN_PATH, []string{"http", "-s", "127.0.0.1:20000", "-t", "123", "-u", "test", "-n", "udp_test", "-l", "10704", "--custom_domain", "127.0.0.1"}) diff --git a/tests/ci/health/health_test.go b/tests/ci/health/health_test.go index 0e75ad22fab6751ca62f981cd266d13fd522cc01..102511a64857ca600d1b77f98ca0e6ed572a6569 100644 --- a/tests/ci/health/health_test.go +++ b/tests/ci/health/health_test.go @@ -175,7 +175,7 @@ func TestHealthCheck(t *testing.T) { defer frpsProcess.Stop() } - time.Sleep(100 * time.Millisecond) + time.Sleep(500 * time.Millisecond) frpcProcess := util.NewProcess(consts.FRPC_SUB_BIN_PATH, []string{"-c", frpcCfgPath}) err = frpcProcess.Start() diff --git a/tests/ci/normal_test.go b/tests/ci/normal_test.go index e9e349455440938fc048c7277992285507c98c80..f1dba7a1eb8f44130bb1f317f781ae93c3d26d4d 100644 --- a/tests/ci/normal_test.go +++ b/tests/ci/normal_test.go @@ -42,7 +42,7 @@ func TestMain(m *testing.M) { panic(err) } - time.Sleep(200 * time.Millisecond) + time.Sleep(500 * time.Millisecond) p2 := util.NewProcess(consts.FRPC_BIN_PATH, []string{"-c", "./auto_test_frpc.ini"}) if err = p2.Start(); err != nil { panic(err) diff --git a/tests/ci/reconnect_test.go b/tests/ci/reconnect_test.go index 86ab317b31657d1cabd4a5dfc893681c9ae7371a..6455347f8d64b7bbcc619e412f15da0e96cb2fa6 100644 --- a/tests/ci/reconnect_test.go +++ b/tests/ci/reconnect_test.go @@ -56,7 +56,7 @@ func TestReconnect(t *testing.T) { defer frpsProcess.Stop() } - time.Sleep(200 * time.Millisecond) + time.Sleep(500 * time.Millisecond) frpcProcess := util.NewProcess(consts.FRPC_BIN_PATH, []string{"-c", frpcCfgPath}) err = frpcProcess.Start() diff --git a/tests/ci/reload_test.go b/tests/ci/reload_test.go index 73a7a091659da1957597d162b30851bb8608f9e5..ac160fa5c37e01f9ddeb4d89b2f6f058d9d17f1d 100644 --- a/tests/ci/reload_test.go +++ b/tests/ci/reload_test.go @@ -94,7 +94,7 @@ func TestReload(t *testing.T) { defer frpsProcess.Stop() } - time.Sleep(200 * time.Millisecond) + time.Sleep(500 * time.Millisecond) frpcProcess := util.NewProcess(consts.FRPC_BIN_PATH, []string{"-c", frpcCfgPath}) err = frpcProcess.Start() diff --git a/tests/ci/template_test.go b/tests/ci/template_test.go index f136121271f14ff4fe0c53cf183b58cd72199371..0c843cd820fdbca51b0d4073f7e9930edd51b851 100644 --- a/tests/ci/template_test.go +++ b/tests/ci/template_test.go @@ -55,7 +55,7 @@ func TestConfTemplate(t *testing.T) { defer frpsProcess.Stop() } - time.Sleep(200 * time.Millisecond) + time.Sleep(500 * time.Millisecond) frpcProcess := util.NewProcess("env", []string{"FRP_TOKEN=123456", "TCP_REMOTE_PORT=20801", consts.FRPC_BIN_PATH, "-c", frpcCfgPath}) err = frpcProcess.Start()