Skip to content

Commit

Permalink
improve kcp shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
fatedier committed Dec 11, 2018
1 parent a4106ec commit 7c21906
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions client/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ func (ctl *Control) HandleNewProxyResp(inMsg *msg.NewProxyResp) {
}

func (ctl *Control) Close() error {
ctl.pm.Close()
ctl.conn.Close()
return nil
}
Expand Down
5 changes: 3 additions & 2 deletions client/proxy/proxy_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,12 @@ func (pm *ProxyManager) StartProxy(name string, remoteAddr string, serverRespErr
}

func (pm *ProxyManager) Close() {
pm.mu.RLock()
defer pm.mu.RUnlock()
pm.mu.Lock()
defer pm.mu.Unlock()
for _, pxy := range pm.proxies {
pxy.Stop()
}
pm.proxies = make(map[string]*ProxyWrapper)
}

func (pm *ProxyManager) HandleWorkConn(name string, workConn frpNet.Conn) {
Expand Down
1 change: 1 addition & 0 deletions client/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ func (svr *Service) login() (conn frpNet.Conn, session *fmux.Session, err error)

if g.GlbClientCfg.TcpMux {
fmuxCfg := fmux.DefaultConfig()
fmuxCfg.KeepAliveInterval = 20 * time.Second
fmuxCfg.LogOutput = ioutil.Discard
session, err = fmux.Client(conn, fmuxCfg)
if err != nil {
Expand Down
9 changes: 8 additions & 1 deletion cmd/frpc/sub/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,15 @@ var (
serverName string
bindAddr string
bindPort int

kcpDoneCh chan struct{}
)

func init() {
rootCmd.PersistentFlags().StringVarP(&cfgFile, "", "c", "./frpc.ini", "config file of frpc")
rootCmd.PersistentFlags().BoolVarP(&showVersion, "version", "v", false, "version of frpc")

kcpDoneCh = make(chan struct{})
}

var rootCmd = &cobra.Command{
Expand Down Expand Up @@ -106,7 +110,7 @@ func handleSignal(svr *client.Service) {
<-ch
svr.Close()
time.Sleep(250 * time.Millisecond)
os.Exit(0)
close(kcpDoneCh)
}

func parseClientCommonCfg(fileType int, content string) (err error) {
Expand Down Expand Up @@ -209,5 +213,8 @@ func startService(pxyCfgs map[string]config.ProxyConf, visitorCfgs map[string]co
}

err = svr.Run()
if g.GlbClientCfg.Protocol == "kcp" {
<-kcpDoneCh
}
return
}
1 change: 1 addition & 0 deletions server/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ func (svr *Service) HandleListener(l frpNet.Listener) {

if g.GlbServerCfg.TcpMux {
fmuxCfg := fmux.DefaultConfig()
fmuxCfg.KeepAliveInterval = 20 * time.Second
fmuxCfg.LogOutput = ioutil.Discard
session, err := fmux.Server(frpConn, fmuxCfg)
if err != nil {
Expand Down

0 comments on commit 7c21906

Please sign in to comment.