Merge pull request #1377 from DaydreamCoding/fix/lifecycle-stop-duplicate-close
fix(lifecycle): TokenRefreshService Stop() 防重复 close
This commit is contained in:
@@ -32,8 +32,9 @@ type TokenRefreshService struct {
|
|||||||
privacyClientFactory PrivacyClientFactory
|
privacyClientFactory PrivacyClientFactory
|
||||||
proxyRepo ProxyRepository
|
proxyRepo ProxyRepository
|
||||||
|
|
||||||
stopCh chan struct{}
|
stopCh chan struct{}
|
||||||
wg sync.WaitGroup
|
stopOnce sync.Once
|
||||||
|
wg sync.WaitGroup
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewTokenRefreshService 创建token刷新服务
|
// NewTokenRefreshService 创建token刷新服务
|
||||||
@@ -130,7 +131,9 @@ func (s *TokenRefreshService) Start() {
|
|||||||
|
|
||||||
// Stop 停止刷新服务(可安全多次调用)
|
// Stop 停止刷新服务(可安全多次调用)
|
||||||
func (s *TokenRefreshService) Stop() {
|
func (s *TokenRefreshService) Stop() {
|
||||||
close(s.stopCh)
|
s.stopOnce.Do(func() {
|
||||||
|
close(s.stopCh)
|
||||||
|
})
|
||||||
s.wg.Wait()
|
s.wg.Wait()
|
||||||
slog.Info("token_refresh.service_stopped")
|
slog.Info("token_refresh.service_stopped")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user