perf: speed up graceful shutdown

移除关闭时等待信号量释放的逻辑,直接标记任务为暂停状态。
超时时间从 10 秒减少到 3 秒,加快进程退出速度。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-10 08:59:25 +08:00
parent a643f185a1
commit ad31301e10
+2 -13
View File
@@ -85,22 +85,11 @@ func mustRunServer() {
// gracefulShutdown 优雅退出:保存任务状态并关闭服务
func gracefulShutdown() {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
defer cancel()
// 等待活跃任务完成或超时
task.GlobalTaskMux.Lock()
activeCount := len(task.GlobalTaskList)
task.GlobalTaskMux.Unlock()
if activeCount > 0 {
logger.Infof("等待 %d 个活跃任务完成(最多10秒)...", activeCount)
// 标记所有运行中的任务为暂停状态
// 标记所有运行中的任务为暂停状态(立即中断,不等待)
task.MarkAllTasksPaused()
// 等待下载信号量释放
task.GlobalDownloadSem.Wait()
task.GlobalMergeSem.Wait()
}
// 关闭 HTTP 服务器
if err := server.Shutdown(ctx); err != nil {