From 6481870d039a0e934c63525511c60da4ae3400ef Mon Sep 17 00:00:00 2001 From: Colin Adler Date: Wed, 13 Apr 2022 23:14:19 -0400 Subject: [PATCH] fix: data races when accessing `github.com/fatedier/frp/client.(*Service).ctl` (#2891) * fix: data race in client/service.go * review fixes --- client/service.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/client/service.go b/client/service.go index 0eab4036..eb592357 100644 --- a/client/service.go +++ b/client/service.go @@ -356,6 +356,8 @@ func (svr *Service) ReloadConf(pxyCfgs map[string]config.ProxyConf, visitorCfgs svr.visitorCfgs = visitorCfgs svr.cfgMu.Unlock() + svr.ctlMu.RLock() + defer svr.ctlMu.RUnlock() return svr.ctl.ReloadConf(pxyCfgs, visitorCfgs) } @@ -365,8 +367,12 @@ func (svr *Service) Close() { func (svr *Service) GracefulClose(d time.Duration) { atomic.StoreUint32(&svr.exit, 1) + + svr.ctlMu.RLock() if svr.ctl != nil { svr.ctl.GracefulClose(d) } + svr.ctlMu.RUnlock() + svr.cancel() }