fix: data race in client/service.go
This commit is contained in:
parent
a7a4ba270d
commit
c89c1943e4
@ -174,7 +174,10 @@ func (svr *Service) keepControllerWorking() {
|
|||||||
reconnectCounts := 1
|
reconnectCounts := 1
|
||||||
|
|
||||||
for {
|
for {
|
||||||
<-svr.ctl.ClosedDoneCh()
|
svr.ctlMu.RLock()
|
||||||
|
ctlCh := svr.ctl.ClosedDoneCh()
|
||||||
|
svr.ctlMu.RUnlock()
|
||||||
|
<-ctlCh
|
||||||
if atomic.LoadUint32(&svr.exit) != 0 {
|
if atomic.LoadUint32(&svr.exit) != 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -356,6 +359,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.Lock()
|
||||||
|
defer svr.ctlMu.Unlock()
|
||||||
return svr.ctl.ReloadConf(pxyCfgs, visitorCfgs)
|
return svr.ctl.ReloadConf(pxyCfgs, visitorCfgs)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -365,8 +370,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.Lock()
|
||||||
if svr.ctl != nil {
|
if svr.ctl != nil {
|
||||||
svr.ctl.GracefulClose(d)
|
svr.ctl.GracefulClose(d)
|
||||||
}
|
}
|
||||||
|
svr.ctlMu.Unlock()
|
||||||
|
|
||||||
svr.cancel()
|
svr.cancel()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user