fix(server): 添加 shutdownServers nil ctx 防御性检查

防止 ctx 参数为 nil 时导致 panic:
- nil ctx 时使用 context.Background() 作为默认值
- 防御性检查确保函数健壮性

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
xfy 2026-04-20 08:26:51 +08:00
parent d856e3c570
commit 28be9e7e66

View File

@ -1138,6 +1138,10 @@ func (s *Server) registerProxyRoutes(router *handler.Router, serverCfg *config.S
// 返回值:
// - error: 聚合错误,无错误或全部成功时返回 nil
func shutdownServers(ctx context.Context, servers []*fasthttp.Server) error {
// 防御性检查nil ctx 使用默认背景
if ctx == nil {
ctx = context.Background()
}
if len(servers) == 0 {
return nil
}