From 9bb08396c78c0595c3aeb3053141892f77de25b0 Mon Sep 17 00:00:00 2001 From: itcode <235832289@qq.com> Date: Wed, 8 Aug 2018 10:52:08 +0800 Subject: [PATCH] Fix the problem of long connection for more than 30 seconds and disconnection of the server --- cmd/frps/root.go | 3 +++ conf/frps_full.ini | 3 +++ models/config/server_common.go | 11 +++++++++++ utils/vhost/newhttp.go | 3 ++- 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/cmd/frps/root.go b/cmd/frps/root.go index fb19f53..8afc3da 100644 --- a/cmd/frps/root.go +++ b/cmd/frps/root.go @@ -60,6 +60,7 @@ var ( allowPorts string maxPoolCount int64 maxPortsPerClient int64 + vhostHttpTimeout int64 ) func init() { @@ -85,6 +86,7 @@ func init() { rootCmd.PersistentFlags().Int64VarP(&authTimeout, "auth_timeout", "", 900, "auth timeout") rootCmd.PersistentFlags().StringVarP(&subDomainHost, "subdomain_host", "", "", "subdomain host") rootCmd.PersistentFlags().Int64VarP(&maxPortsPerClient, "max_ports_per_client", "", 0, "max ports per client") + rootCmd.PersistentFlags().Int64VarP(&vhostHttpTimeout, "vhost_http_timeout", "", 30, "vhost http timeout") } var rootCmd = &cobra.Command{ @@ -177,6 +179,7 @@ func parseServerCommonCfgFromCmd() (err error) { g.GlbServerCfg.AuthTimeout = authTimeout g.GlbServerCfg.SubDomainHost = subDomainHost g.GlbServerCfg.MaxPortsPerClient = maxPortsPerClient + g.GlbServerCfg.VhostHttpTimeout = vhostHttpTimeout return } diff --git a/conf/frps_full.ini b/conf/frps_full.ini index 586b967..4b61fac 100644 --- a/conf/frps_full.ini +++ b/conf/frps_full.ini @@ -66,3 +66,6 @@ subdomain_host = frps.com # if tcp stream multiplexing is used, default is true tcp_mux = true + +# if long connection for more than 30 seconds and disconnection of the server ,fix the pars . +vhost_http_timeout = 30 \ No newline at end of file diff --git a/models/config/server_common.go b/models/config/server_common.go index 19e1a1d..a92b9d2 100644 --- a/models/config/server_common.go +++ b/models/config/server_common.go @@ -73,6 +73,7 @@ type ServerCommonConf struct { MaxPortsPerClient int64 `json:"max_ports_per_client"` HeartBeatTimeout int64 `json:"heart_beat_timeout"` UserConnTimeout int64 `json:"user_conn_timeout"` + VhostHttpTimeout int64 `json:"vhost_http_timeout "` } func GetDefaultServerConf() *ServerCommonConf { @@ -102,6 +103,7 @@ func GetDefaultServerConf() *ServerCommonConf { MaxPortsPerClient: 0, HeartBeatTimeout: 90, UserConnTimeout: 10, + VhostHttpTimeout: 30, } } @@ -300,6 +302,15 @@ func UnmarshalServerConfFromIni(defaultCfg *ServerCommonConf, content string) (c cfg.HeartBeatTimeout = v } } + if tmpStr, ok = conf.Get("common", "vhost_http_timeout"); ok { + v, errRet := strconv.ParseInt(tmpStr, 10, 64) + if errRet != nil { + err = fmt.Errorf("Parse conf error: vhost_http_timeout is incorrect") + return + } else { + cfg.VhostHttpTimeout = v + } + } return } diff --git a/utils/vhost/newhttp.go b/utils/vhost/newhttp.go index 1351b22..6cfadf9 100644 --- a/utils/vhost/newhttp.go +++ b/utils/vhost/newhttp.go @@ -25,13 +25,14 @@ import ( "sync" "time" + "github.com/fatedier/frp/g" frpLog "github.com/fatedier/frp/utils/log" "github.com/fatedier/golib/pool" ) var ( - responseHeaderTimeout = time.Duration(30) * time.Second + responseHeaderTimeout = time.Duration(g.GlbServerCfg.VhostHttpTimeout) * time.Second ErrRouterConfigConflict = errors.New("router config conflict") ErrNoDomain = errors.New("no such domain")