diff --git a/cmd/frpc/main.go b/cmd/frpc/main.go index 51eb53c..845f4f7 100644 --- a/cmd/frpc/main.go +++ b/cmd/frpc/main.go @@ -86,7 +86,7 @@ func main() { if args["reload"] != nil { if args["reload"].(bool) { if err = CmdReload(); err != nil { - fmt.Printf("frps reload error: %v\n", err) + fmt.Printf("frpc reload error: %v\n", err) os.Exit(1) } else { fmt.Printf("reload success\n") diff --git a/conf/frpc_full.ini b/conf/frpc_full.ini index 1204b26..4bec160 100644 --- a/conf/frpc_full.ini +++ b/conf/frpc_full.ini @@ -73,7 +73,7 @@ local_port = 22 # if remote_port is 0, frps will assgin a random port for you remote_port = 0 -# if you want tp expose multiple ports, add 'range:' prefix to the section name +# if you want to expose multiple ports, add 'range:' prefix to the section name # frpc will generate multiple proxies such as 'tcp_port_6010', 'tcp_port_6011' and so on. [range:tcp_port] type = tcp diff --git a/models/proto/udp/udp.go b/models/proto/udp/udp.go index fe548f1..15ecb9c 100644 --- a/models/proto/udp/udp.go +++ b/models/proto/udp/udp.go @@ -82,6 +82,7 @@ func Forwarder(dstAddr *net.UDPAddr, readCh <-chan *msg.UdpPacket, sendCh chan<- mu.Lock() delete(udpConnMap, addr) mu.Unlock() + udpConn.Close() }() buf := pool.GetBuf(1500) diff --git a/server/control.go b/server/control.go index dbb99ad..d7938e7 100644 --- a/server/control.go +++ b/server/control.go @@ -265,13 +265,14 @@ func (ctl *Control) stoper() { ctl.conn.Close() ctl.readerShutdown.WaitDone() + ctl.mu.Lock() + defer ctl.mu.Unlock() + close(ctl.workConnCh) for workConn := range ctl.workConnCh { workConn.Close() } - ctl.mu.Lock() - defer ctl.mu.Unlock() for _, pxy := range ctl.proxies { pxy.Close() ctl.svr.DelProxy(pxy.GetName()) @@ -303,6 +304,7 @@ func (ctl *Control) manager() { if time.Since(ctl.lastPing) > time.Duration(config.ServerCommonCfg.HeartBeatTimeout)*time.Second { ctl.conn.Warn("heartbeat timeout") ctl.allShutdown.Start() + return } case rawMsg, ok := <-ctl.readCh: if !ok { diff --git a/utils/net/conn.go b/utils/net/conn.go index 78319cc..b187733 100644 --- a/utils/net/conn.go +++ b/utils/net/conn.go @@ -21,6 +21,7 @@ import ( "io" "net" "sync" + "sync/atomic" "time" "github.com/fatedier/frp/utils/log" @@ -178,6 +179,7 @@ func (sc *SharedConn) WriteBuff(buffer []byte) (err error) { type StatsConn struct { Conn + closed int64 // 1 means closed totalRead int64 totalWrite int64 statsFunc func(totalRead, totalWrite int64) @@ -203,9 +205,12 @@ func (statsConn *StatsConn) Write(p []byte) (n int, err error) { } func (statsConn *StatsConn) Close() (err error) { - err = statsConn.Conn.Close() - if statsConn.statsFunc != nil { - statsConn.statsFunc(statsConn.totalRead, statsConn.totalWrite) + old := atomic.SwapInt64(&statsConn.closed, 1) + if old != 1 { + err = statsConn.Conn.Close() + if statsConn.statsFunc != nil { + statsConn.statsFunc(statsConn.totalRead, statsConn.totalWrite) + } } return }