mirror of
https://gitee.com/IrisVega/frp.git
synced 2024-11-01 22:31:29 +08:00
client: reconnect more quickly if it's a dial error (#2240)
This commit is contained in:
parent
976fd81d4d
commit
8fcd4f4a95
@ -17,6 +17,7 @@ package client
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net"
|
"net"
|
||||||
@ -177,10 +178,17 @@ func (svr *Service) keepControllerWorking() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
xl.Warn("reconnect to server error: %v", err)
|
xl.Warn("reconnect to server error: %v", err)
|
||||||
time.Sleep(delayTime)
|
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
|
delayTime = delayTime * 2
|
||||||
if delayTime > maxDelayTime {
|
if delayTime > maxDelayTime {
|
||||||
delayTime = maxDelayTime
|
delayTime = maxDelayTime
|
||||||
}
|
}
|
||||||
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// reconnect success, init delayTime
|
// reconnect success, init delayTime
|
||||||
|
@ -23,7 +23,6 @@ import (
|
|||||||
"gopkg.in/ini.v1"
|
"gopkg.in/ini.v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
// Visitor
|
// Visitor
|
||||||
var (
|
var (
|
||||||
visitorConfTypeMap = map[string]reflect.Type{
|
visitorConfTypeMap = map[string]reflect.Type{
|
||||||
@ -64,7 +63,6 @@ type XTCPVisitorConf struct {
|
|||||||
BaseVisitorConf `ini:",extends" json:"inline"`
|
BaseVisitorConf `ini:",extends" json:"inline"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// DefaultVisitorConf creates a empty VisitorConf object by visitorType.
|
// DefaultVisitorConf creates a empty VisitorConf object by visitorType.
|
||||||
// If visitorType doesn't exist, return nil.
|
// If visitorType doesn't exist, return nil.
|
||||||
func DefaultVisitorConf(visitorType string) VisitorConf {
|
func DefaultVisitorConf(visitorType string) VisitorConf {
|
||||||
|
@ -19,8 +19,8 @@ import (
|
|||||||
|
|
||||||
"github.com/fatedier/frp/pkg/consts"
|
"github.com/fatedier/frp/pkg/consts"
|
||||||
|
|
||||||
"gopkg.in/ini.v1"
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
"gopkg.in/ini.v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
const testVisitorPrefix = "test."
|
const testVisitorPrefix = "test."
|
||||||
|
@ -19,7 +19,7 @@ func TestCmdTCP(t *testing.T) {
|
|||||||
if assert.NoError(err) {
|
if assert.NoError(err) {
|
||||||
defer s.Stop()
|
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",
|
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"})
|
"-l", "10701", "-r", "20801", "-n", "tcp_test"})
|
||||||
@ -43,7 +43,7 @@ func TestCmdUDP(t *testing.T) {
|
|||||||
if assert.NoError(err) {
|
if assert.NoError(err) {
|
||||||
defer s.Stop()
|
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",
|
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"})
|
"-l", "10702", "-r", "20802", "-n", "udp_test"})
|
||||||
@ -67,7 +67,7 @@ func TestCmdHTTP(t *testing.T) {
|
|||||||
if assert.NoError(err) {
|
if assert.NoError(err) {
|
||||||
defer s.Stop()
|
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",
|
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"})
|
"-n", "udp_test", "-l", "10704", "--custom_domain", "127.0.0.1"})
|
||||||
|
@ -175,7 +175,7 @@ func TestHealthCheck(t *testing.T) {
|
|||||||
defer frpsProcess.Stop()
|
defer frpsProcess.Stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
time.Sleep(500 * time.Millisecond)
|
||||||
|
|
||||||
frpcProcess := util.NewProcess(consts.FRPC_SUB_BIN_PATH, []string{"-c", frpcCfgPath})
|
frpcProcess := util.NewProcess(consts.FRPC_SUB_BIN_PATH, []string{"-c", frpcCfgPath})
|
||||||
err = frpcProcess.Start()
|
err = frpcProcess.Start()
|
||||||
|
@ -42,7 +42,7 @@ func TestMain(m *testing.M) {
|
|||||||
panic(err)
|
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"})
|
p2 := util.NewProcess(consts.FRPC_BIN_PATH, []string{"-c", "./auto_test_frpc.ini"})
|
||||||
if err = p2.Start(); err != nil {
|
if err = p2.Start(); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
@ -56,7 +56,7 @@ func TestReconnect(t *testing.T) {
|
|||||||
defer frpsProcess.Stop()
|
defer frpsProcess.Stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
time.Sleep(200 * time.Millisecond)
|
time.Sleep(500 * time.Millisecond)
|
||||||
|
|
||||||
frpcProcess := util.NewProcess(consts.FRPC_BIN_PATH, []string{"-c", frpcCfgPath})
|
frpcProcess := util.NewProcess(consts.FRPC_BIN_PATH, []string{"-c", frpcCfgPath})
|
||||||
err = frpcProcess.Start()
|
err = frpcProcess.Start()
|
||||||
|
@ -94,7 +94,7 @@ func TestReload(t *testing.T) {
|
|||||||
defer frpsProcess.Stop()
|
defer frpsProcess.Stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
time.Sleep(200 * time.Millisecond)
|
time.Sleep(500 * time.Millisecond)
|
||||||
|
|
||||||
frpcProcess := util.NewProcess(consts.FRPC_BIN_PATH, []string{"-c", frpcCfgPath})
|
frpcProcess := util.NewProcess(consts.FRPC_BIN_PATH, []string{"-c", frpcCfgPath})
|
||||||
err = frpcProcess.Start()
|
err = frpcProcess.Start()
|
||||||
|
@ -55,7 +55,7 @@ func TestConfTemplate(t *testing.T) {
|
|||||||
defer frpsProcess.Stop()
|
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})
|
frpcProcess := util.NewProcess("env", []string{"FRP_TOKEN=123456", "TCP_REMOTE_PORT=20801", consts.FRPC_BIN_PATH, "-c", frpcCfgPath})
|
||||||
err = frpcProcess.Start()
|
err = frpcProcess.Start()
|
||||||
|
Loading…
Reference in New Issue
Block a user