Skip to content

Commit

Permalink
fix: kcp protocol cause delay release resource (fatedier#2621)
Browse files Browse the repository at this point in the history
Co-authored-by: blizard863 <[email protected]>
  • Loading branch information
bingtianbaihua and detry863 authored Oct 19, 2021
1 parent 998e678 commit 1d26ea4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
9 changes: 8 additions & 1 deletion client/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,16 @@ func (ctl *Control) HandleNewProxyResp(inMsg *msg.NewProxyResp) {
}

func (ctl *Control) Close() error {
return ctl.GracefulClose(0)
}

func (ctl *Control) GracefulClose(t time.Duration) error {
ctl.pm.Close()
ctl.conn.Close()
ctl.vm.Close()

time.Sleep(t)

ctl.conn.Close()
if ctl.session != nil {
ctl.session.Close()
}
Expand Down
8 changes: 6 additions & 2 deletions client/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,10 +311,14 @@ func (svr *Service) ReloadConf(pxyCfgs map[string]config.ProxyConf, visitorCfgs
return svr.ctl.ReloadConf(pxyCfgs, visitorCfgs)
}

func (svr *Service) Close() {
func (svr *Service) Close(t time.Duration) {
atomic.StoreUint32(&svr.exit, 1)
if svr.ctl != nil {
svr.ctl.Close()
if t > 0 {
svr.ctl.GracefulClose(t)
} else {
svr.ctl.Close()
}
}
svr.cancel()
}
3 changes: 1 addition & 2 deletions cmd/frpc/sub/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,7 @@ func handleSignal(svr *client.Service) {
ch := make(chan os.Signal)
signal.Notify(ch, syscall.SIGINT, syscall.SIGTERM)
<-ch
svr.Close()
time.Sleep(250 * time.Millisecond)
svr.Close(time.Millisecond * 250)
close(kcpDoneCh)
}

Expand Down

0 comments on commit 1d26ea4

Please sign in to comment.