修复服务退出超时问题

This commit is contained in:
2025-03-05 14:50:50 +08:00
parent 0144d1d46f
commit 6e2309df2d
3 changed files with 12 additions and 25 deletions

View File

@@ -27,7 +27,6 @@ type Service struct {
cancel context.CancelFunc
userConnMap sync.Map
ctrlConnMap sync.Map
fwdLesWg utils.CountWaitGroup
ctrlConnWg utils.CountWaitGroup
@@ -42,11 +41,11 @@ func New(config *Config) *Service {
ctx, cancel := context.WithCancel(context.Background())
return &Service{
Config: config,
ctx: ctx,
cancel: cancel,
Config: config,
ctx: ctx,
cancel: cancel,
userConnMap: sync.Map{},
ctrlConnMap: sync.Map{},
fwdLesWg: utils.CountWaitGroup{},
ctrlConnWg: utils.CountWaitGroup{},
@@ -101,7 +100,6 @@ func (s *Service) Run() {
}
wg.Wait()
// 协程建立有先后顺序,不能乱,否则会泄露
s.dataConnWg.Wait()
s.ctrlConnWg.Wait()
s.fwdLesWg.Wait()
@@ -115,13 +113,6 @@ func (s *Service) Run() {
})
s.userConnMap.Clear()
s.ctrlConnMap.Range(func(key, value any) bool {
conn := value.(net.Conn)
utils.Close(conn)
return true
})
s.ctrlConnMap.Clear()
s.ctrlConnWg.Wait()
slog.Debug("控制通道连接已关闭")
s.dataConnWg.Wait()