client: reconnect more quickly if it's a dial error (#2240)

This commit is contained in:
fatedier 2021-02-18 16:15:35 +08:00 committed by GitHub
parent 976fd81d4d
commit 8fcd4f4a95
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 20 additions and 14 deletions

View File

@ -17,6 +17,7 @@ package client
import (
"context"
"crypto/tls"
"errors"
"fmt"
"io/ioutil"
"net"
@ -177,10 +178,17 @@ func (svr *Service) keepControllerWorking() {
if err != nil {
xl.Warn("reconnect to server error: %v", err)
time.Sleep(delayTime)
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
}
// reconnect success, init delayTime

View File

@ -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 {

View File

@ -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."

View File

@ -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"})

View File

@ -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()

View File

@ -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)

View File

@ -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()

View File

@ -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()

View File

@ -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()