timeout exit frpc
This commit is contained in:
parent
293003fcdb
commit
443ce4806c
@ -19,6 +19,7 @@ import (
|
|||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
|
"os"
|
||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
@ -87,6 +88,8 @@ type Control struct {
|
|||||||
|
|
||||||
// sets authentication based on selected method
|
// sets authentication based on selected method
|
||||||
authSetter auth.Setter
|
authSetter auth.Setter
|
||||||
|
|
||||||
|
timeOutExit int64
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewControl(ctx context.Context, runID string, conn net.Conn, session *fmux.Session,
|
func NewControl(ctx context.Context, runID string, conn net.Conn, session *fmux.Session,
|
||||||
@ -114,6 +117,7 @@ func NewControl(ctx context.Context, runID string, conn net.Conn, session *fmux.
|
|||||||
xl: xlog.FromContextSafe(ctx),
|
xl: xlog.FromContextSafe(ctx),
|
||||||
ctx: ctx,
|
ctx: ctx,
|
||||||
authSetter: authSetter,
|
authSetter: authSetter,
|
||||||
|
timeOutExit: clientCfg.TimeOutExit,
|
||||||
}
|
}
|
||||||
ctl.pm = proxy.NewManager(ctl.ctx, ctl.sendCh, clientCfg, serverUDPPort)
|
ctl.pm = proxy.NewManager(ctl.ctx, ctl.sendCh, clientCfg, serverUDPPort)
|
||||||
|
|
||||||
@ -341,6 +345,13 @@ func (ctl *Control) msgHandler() {
|
|||||||
}
|
}
|
||||||
ctl.sendCh <- pingMsg
|
ctl.sendCh <- pingMsg
|
||||||
case <-hbCheckCh:
|
case <-hbCheckCh:
|
||||||
|
if ctl.clientCfg.TimeOutExit > 0 {
|
||||||
|
ctl.timeOutExit--
|
||||||
|
if ctl.timeOutExit <= 0 {
|
||||||
|
xl.Debug("exit --------------------", ctl.timeOutExit)
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
}
|
||||||
if time.Since(ctl.lastPong) > time.Duration(ctl.clientCfg.HeartbeatTimeout)*time.Second {
|
if time.Since(ctl.lastPong) > time.Duration(ctl.clientCfg.HeartbeatTimeout)*time.Second {
|
||||||
xl.Warn("heartbeat timeout")
|
xl.Warn("heartbeat timeout")
|
||||||
// let reader() stop
|
// let reader() stop
|
||||||
@ -354,8 +365,10 @@ func (ctl *Control) msgHandler() {
|
|||||||
|
|
||||||
switch m := rawMsg.(type) {
|
switch m := rawMsg.(type) {
|
||||||
case *msg.ReqWorkConn:
|
case *msg.ReqWorkConn:
|
||||||
|
ctl.timeOutExit = ctl.clientCfg.TimeOutExit
|
||||||
go ctl.HandleReqWorkConn(m)
|
go ctl.HandleReqWorkConn(m)
|
||||||
case *msg.NewProxyResp:
|
case *msg.NewProxyResp:
|
||||||
|
ctl.timeOutExit = ctl.clientCfg.TimeOutExit
|
||||||
ctl.HandleNewProxyResp(m)
|
ctl.HandleNewProxyResp(m)
|
||||||
case *msg.Pong:
|
case *msg.Pong:
|
||||||
if m.Error != "" {
|
if m.Error != "" {
|
||||||
|
@ -72,6 +72,7 @@ var (
|
|||||||
bindPort int
|
bindPort int
|
||||||
|
|
||||||
tlsEnable bool
|
tlsEnable bool
|
||||||
|
timeOutExit int
|
||||||
|
|
||||||
kcpDoneCh chan struct{}
|
kcpDoneCh chan struct{}
|
||||||
)
|
)
|
||||||
@ -93,6 +94,7 @@ func RegisterCommonFlags(cmd *cobra.Command) {
|
|||||||
cmd.PersistentFlags().IntVarP(&logMaxDays, "log_max_days", "", 3, "log file reversed days")
|
cmd.PersistentFlags().IntVarP(&logMaxDays, "log_max_days", "", 3, "log file reversed days")
|
||||||
cmd.PersistentFlags().BoolVarP(&disableLogColor, "disable_log_color", "", false, "disable log color in console")
|
cmd.PersistentFlags().BoolVarP(&disableLogColor, "disable_log_color", "", false, "disable log color in console")
|
||||||
cmd.PersistentFlags().BoolVarP(&tlsEnable, "tls_enable", "", false, "enable frpc tls")
|
cmd.PersistentFlags().BoolVarP(&tlsEnable, "tls_enable", "", false, "enable frpc tls")
|
||||||
|
cmd.PersistentFlags().IntVarP(&timeOutExit, "timeout_exit", "", -1, "time out exit frpc")
|
||||||
}
|
}
|
||||||
|
|
||||||
var rootCmd = &cobra.Command{
|
var rootCmd = &cobra.Command{
|
||||||
@ -150,7 +152,7 @@ func parseClientCommonCfgFromCmd() (cfg config.ClientCommonConf, err error) {
|
|||||||
cfg.LogFile = logFile
|
cfg.LogFile = logFile
|
||||||
cfg.LogMaxDays = int64(logMaxDays)
|
cfg.LogMaxDays = int64(logMaxDays)
|
||||||
cfg.DisableLogColor = disableLogColor
|
cfg.DisableLogColor = disableLogColor
|
||||||
|
cfg.TimeOutExit = int64(timeOutExit)
|
||||||
// Only token authentication is supported in cmd mode
|
// Only token authentication is supported in cmd mode
|
||||||
cfg.ClientConfig = auth.GetDefaultClientConf()
|
cfg.ClientConfig = auth.GetDefaultClientConf()
|
||||||
cfg.Token = token
|
cfg.Token = token
|
||||||
|
@ -145,6 +145,8 @@ type ClientCommonConf struct {
|
|||||||
UDPPacketSize int64 `ini:"udp_packet_size" json:"udp_packet_size"`
|
UDPPacketSize int64 `ini:"udp_packet_size" json:"udp_packet_size"`
|
||||||
// Include other config files for proxies.
|
// Include other config files for proxies.
|
||||||
IncludeConfigFiles []string `ini:"includes" json:"includes"`
|
IncludeConfigFiles []string `ini:"includes" json:"includes"`
|
||||||
|
// There is no data interaction between frpc and frps, timeout exit
|
||||||
|
TimeOutExit int64 `ini:"timeout_exit" json:"timeout_exit"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetDefaultClientConf returns a client configuration with default values.
|
// GetDefaultClientConf returns a client configuration with default values.
|
||||||
|
Loading…
Reference in New Issue
Block a user