improve kcp shutdown

This commit is contained in:
fatedier 2018-12-11 15:06:54 +08:00
parent a4106ec4b7
commit 7c21906884
5 changed files with 14 additions and 3 deletions

View File

@ -145,6 +145,7 @@ func (ctl *Control) HandleNewProxyResp(inMsg *msg.NewProxyResp) {
} }
func (ctl *Control) Close() error { func (ctl *Control) Close() error {
ctl.pm.Close()
ctl.conn.Close() ctl.conn.Close()
return nil return nil
} }

View File

@ -50,11 +50,12 @@ func (pm *ProxyManager) StartProxy(name string, remoteAddr string, serverRespErr
} }
func (pm *ProxyManager) Close() { func (pm *ProxyManager) Close() {
pm.mu.RLock() pm.mu.Lock()
defer pm.mu.RUnlock() defer pm.mu.Unlock()
for _, pxy := range pm.proxies { for _, pxy := range pm.proxies {
pxy.Stop() pxy.Stop()
} }
pm.proxies = make(map[string]*ProxyWrapper)
} }
func (pm *ProxyManager) HandleWorkConn(name string, workConn frpNet.Conn) { func (pm *ProxyManager) HandleWorkConn(name string, workConn frpNet.Conn) {

View File

@ -157,6 +157,7 @@ func (svr *Service) login() (conn frpNet.Conn, session *fmux.Session, err error)
if g.GlbClientCfg.TcpMux { if g.GlbClientCfg.TcpMux {
fmuxCfg := fmux.DefaultConfig() fmuxCfg := fmux.DefaultConfig()
fmuxCfg.KeepAliveInterval = 20 * time.Second
fmuxCfg.LogOutput = ioutil.Discard fmuxCfg.LogOutput = ioutil.Discard
session, err = fmux.Client(conn, fmuxCfg) session, err = fmux.Client(conn, fmuxCfg)
if err != nil { if err != nil {

View File

@ -68,11 +68,15 @@ var (
serverName string serverName string
bindAddr string bindAddr string
bindPort int bindPort int
kcpDoneCh chan struct{}
) )
func init() { func init() {
rootCmd.PersistentFlags().StringVarP(&cfgFile, "", "c", "./frpc.ini", "config file of frpc") rootCmd.PersistentFlags().StringVarP(&cfgFile, "", "c", "./frpc.ini", "config file of frpc")
rootCmd.PersistentFlags().BoolVarP(&showVersion, "version", "v", false, "version of frpc") rootCmd.PersistentFlags().BoolVarP(&showVersion, "version", "v", false, "version of frpc")
kcpDoneCh = make(chan struct{})
} }
var rootCmd = &cobra.Command{ var rootCmd = &cobra.Command{
@ -106,7 +110,7 @@ func handleSignal(svr *client.Service) {
<-ch <-ch
svr.Close() svr.Close()
time.Sleep(250 * time.Millisecond) time.Sleep(250 * time.Millisecond)
os.Exit(0) close(kcpDoneCh)
} }
func parseClientCommonCfg(fileType int, content string) (err error) { func parseClientCommonCfg(fileType int, content string) (err error) {
@ -209,5 +213,8 @@ func startService(pxyCfgs map[string]config.ProxyConf, visitorCfgs map[string]co
} }
err = svr.Run() err = svr.Run()
if g.GlbClientCfg.Protocol == "kcp" {
<-kcpDoneCh
}
return return
} }

View File

@ -290,6 +290,7 @@ func (svr *Service) HandleListener(l frpNet.Listener) {
if g.GlbServerCfg.TcpMux { if g.GlbServerCfg.TcpMux {
fmuxCfg := fmux.DefaultConfig() fmuxCfg := fmux.DefaultConfig()
fmuxCfg.KeepAliveInterval = 20 * time.Second
fmuxCfg.LogOutput = ioutil.Discard fmuxCfg.LogOutput = ioutil.Discard
session, err := fmux.Server(frpConn, fmuxCfg) session, err := fmux.Server(frpConn, fmuxCfg)
if err != nil { if err != nil {