@@ -368,8 +368,8 @@ func (cp *commonPage) network(c *gin.Context) {
368368 err error
369369 }
370370
371- // 创建带超时的context
372- ctx , cancel := context .WithTimeout (c . Request . Context (), 10 * time .Second )
371+ // 创建带超时的context,使用独立context避免受请求状态影响
372+ ctx , cancel := context .WithTimeout (context . Background (), 10 * time .Second )
373373 defer cancel ()
374374
375375 // 创建通道收集结果
@@ -588,8 +588,8 @@ func (cp *commonPage) getServerStat(c *gin.Context, withPublicNote bool) ([]byte
588588 _ , isViewPasswordVerfied := c .Get (model .CtxKeyViewPasswordVerified )
589589 authorized := isMember || isViewPasswordVerfied
590590
591- // 添加超时控制,防止长时间阻塞 - 延长超时时间避免与WebSocket冲突
592- ctx , cancel := context .WithTimeout (c . Request . Context (), 10 * time .Second )
591+ // 使用独立的context,不受WebSocket连接状态影响
592+ ctx , cancel := context .WithTimeout (context . Background (), 10 * time .Second )
593593 defer cancel ()
594594
595595 v , err , _ := cp .requestGroup .Do (fmt .Sprintf ("serverStats::%t" , authorized ), func () (interface {}, error ) {
@@ -1177,12 +1177,14 @@ func (cp *commonPage) ws(c *gin.Context) {
11771177 case <- done : // 从读取goroutine接收到退出信号
11781178 return
11791179 case <- ticker .C :
1180+ // 使用独立的context获取服务器状态,避免受WebSocket连接状态影响
11801181 stat , err := cp .getServerStat (c , false )
11811182 if err != nil {
11821183 if singleton .Conf .Debug {
11831184 log .Printf ("NG-ERROR: failed to get server stat for websocket: %v" , err )
11841185 }
1185- // 不要退出,让 done channel 处理终止
1186+ // 发生错误时等待一下再继续,避免快速重试
1187+ time .Sleep (time .Second )
11861188 continue
11871189 }
11881190 if err = safeConn .WriteMessage (websocket .TextMessage , stat ); err != nil {
0 commit comments