Browse Source

fix: data races when accessing `github.com/fatedier/frp/client.(*Service).ctl` (#2891)

* fix: data race in client/service.go

* review fixes
pull/2894/head
Colin Adler 3 years ago committed by GitHub
parent
commit
6481870d03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      client/service.go

6
client/service.go

@ -356,6 +356,8 @@ func (svr *Service) ReloadConf(pxyCfgs map[string]config.ProxyConf, visitorCfgs
svr.visitorCfgs = visitorCfgs svr.visitorCfgs = visitorCfgs
svr.cfgMu.Unlock() svr.cfgMu.Unlock()
svr.ctlMu.RLock()
defer svr.ctlMu.RUnlock()
return svr.ctl.ReloadConf(pxyCfgs, visitorCfgs) return svr.ctl.ReloadConf(pxyCfgs, visitorCfgs)
} }
@ -365,8 +367,12 @@ func (svr *Service) Close() {
func (svr *Service) GracefulClose(d time.Duration) { func (svr *Service) GracefulClose(d time.Duration) {
atomic.StoreUint32(&svr.exit, 1) atomic.StoreUint32(&svr.exit, 1)
svr.ctlMu.RLock()
if svr.ctl != nil { if svr.ctl != nil {
svr.ctl.GracefulClose(d) svr.ctl.GracefulClose(d)
} }
svr.ctlMu.RUnlock()
svr.cancel() svr.cancel()
} }

Loading…
Cancel
Save