Commit 61607990 authored by QTom's avatar QTom
Browse files

fix(lifecycle): TokenRefreshService Stop() 防重复 close

使用 sync.Once 包裹 close(stopCh),避免多次调用 Stop() 时
触发 panic: close of closed channel。
parent b6527523
...@@ -33,6 +33,7 @@ type TokenRefreshService struct { ...@@ -33,6 +33,7 @@ type TokenRefreshService struct {
proxyRepo ProxyRepository proxyRepo ProxyRepository
stopCh chan struct{} stopCh chan struct{}
stopOnce sync.Once
wg sync.WaitGroup wg sync.WaitGroup
} }
...@@ -130,7 +131,9 @@ func (s *TokenRefreshService) Start() { ...@@ -130,7 +131,9 @@ func (s *TokenRefreshService) Start() {
// Stop 停止刷新服务(可安全多次调用) // Stop 停止刷新服务(可安全多次调用)
func (s *TokenRefreshService) Stop() { func (s *TokenRefreshService) Stop() {
s.stopOnce.Do(func() {
close(s.stopCh) close(s.stopCh)
})
s.wg.Wait() s.wg.Wait()
slog.Info("token_refresh.service_stopped") slog.Info("token_refresh.service_stopped")
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment