修复服务退出超时问题
This commit is contained in:
@@ -38,17 +38,15 @@ func Start() {
|
||||
osQuit := make(chan os.Signal)
|
||||
signal.Notify(osQuit, os.Interrupt, syscall.SIGTERM)
|
||||
|
||||
errQuit := make(chan struct{})
|
||||
defer close(errQuit)
|
||||
|
||||
// 启动服务
|
||||
slog.Info("启动服务")
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
wg := sync.WaitGroup{}
|
||||
|
||||
wg.Add(1)
|
||||
errQuit := make(chan struct{}, 1)
|
||||
defer close(errQuit)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
err := startFwdServer(ctx)
|
||||
@@ -72,14 +70,14 @@ func Start() {
|
||||
timeout, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
|
||||
wg.Wait()
|
||||
|
||||
select {
|
||||
case <-utils.ChanWgWait(timeout, &wg):
|
||||
slog.Info("服务已退出")
|
||||
case <-timeout.Done():
|
||||
slog.Warn("退出超时,强制退出")
|
||||
}
|
||||
|
||||
time.Sleep(3 * time.Second)
|
||||
}
|
||||
|
||||
func startFwdServer(ctx context.Context) error {
|
||||
|
||||
Reference in New Issue
Block a user