实现节点下线功能,优化控制通道和数据通道的连接处理

This commit is contained in:
2025-05-16 16:59:33 +08:00
parent 8a6a4833d4
commit 22f3c37478
7 changed files with 136 additions and 120 deletions

View File

@@ -17,7 +17,6 @@ import (
"proxy-server/server/report"
"proxy-server/server/web"
"sync"
"syscall"
"time"
"github.com/google/uuid"
@@ -49,7 +48,7 @@ func (s *server) Run() (err error) {
}
// 准备子服务
ctx, cancel := context.WithCancel(context.Background())
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, os.Kill)
defer cancel()
wg := sync.WaitGroup{}
@@ -95,17 +94,16 @@ func (s *server) Run() (err error) {
return fmt.Errorf("服务上线失败: %w", err)
}
// 等待退出信号
osQuit := make(chan os.Signal, 1)
signal.Notify(osQuit, os.Interrupt, syscall.SIGTERM)
select {
case <-osQuit:
slog.Info("服务主动退出")
case <-ctx.Done():
case err := <-fwdQuit:
slog.Warn("fwd 服务异常退出", "err", err)
if err != nil {
slog.Warn("fwd 服务异常退出", "err", err)
}
case err := <-apiQuit:
slog.Warn("web 服务异常退出", "err", err)
if err != nil {
slog.Warn("web 服务异常退出", "err", err)
}
}
cancel()