mirror of
https://github.com/fatedier/frp.git
synced 2025-07-22 22:01:55 +07:00
allow to disable application layer heartbeat to reduce traffic cost (#2758)
fix #2754
This commit is contained in:
@ -400,12 +400,19 @@ func (ctl *Control) manager() {
|
||||
defer ctl.allShutdown.Start()
|
||||
defer ctl.managerShutdown.Done()
|
||||
|
||||
heartbeat := time.NewTicker(time.Second)
|
||||
defer heartbeat.Stop()
|
||||
var heartbeatCh <-chan time.Time
|
||||
if ctl.serverCfg.TCPMux || ctl.serverCfg.HeartbeatTimeout <= 0 {
|
||||
// Don't need application heartbeat here.
|
||||
// yamux will do same thing.
|
||||
} else {
|
||||
heartbeat := time.NewTicker(time.Second)
|
||||
defer heartbeat.Stop()
|
||||
heartbeatCh = heartbeat.C
|
||||
}
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-heartbeat.C:
|
||||
case <-heartbeatCh:
|
||||
if time.Since(ctl.lastPing) > time.Duration(ctl.serverCfg.HeartbeatTimeout)*time.Second {
|
||||
xl.Warn("heartbeat timeout")
|
||||
return
|
||||
|
@ -406,7 +406,7 @@ func (svr *Service) HandleListener(l net.Listener) {
|
||||
go func(ctx context.Context, frpConn net.Conn) {
|
||||
if svr.cfg.TCPMux {
|
||||
fmuxCfg := fmux.DefaultConfig()
|
||||
fmuxCfg.KeepAliveInterval = 20 * time.Second
|
||||
fmuxCfg.KeepAliveInterval = time.Duration(svr.cfg.TCPMuxKeepaliveInterval) * time.Second
|
||||
fmuxCfg.LogOutput = io.Discard
|
||||
session, err := fmux.Server(frpConn, fmuxCfg)
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user