(c *gin.Context, mutex *sync.Mutex)
| 173 | } |
| 174 | |
| 175 | func sendPingData(c *gin.Context, mutex *sync.Mutex) error { |
| 176 | // 增加超时控制,防止锁死等待 |
| 177 | done := make(chan error, 1) |
| 178 | go func() { |
| 179 | mutex.Lock() |
| 180 | defer mutex.Unlock() |
| 181 | |
| 182 | err := helper.PingData(c) |
| 183 | if err != nil { |
| 184 | common2.LogError(c, "SSE ping error: "+err.Error()) |
| 185 | done <- err |
| 186 | return |
| 187 | } |
| 188 | |
| 189 | if common2.DebugEnabled { |
| 190 | println("SSE ping data sent.") |
| 191 | } |
| 192 | done <- nil |
| 193 | }() |
| 194 | |
| 195 | // 设置发送ping数据的超时时间 |
| 196 | select { |
| 197 | case err := <-done: |
| 198 | return err |
| 199 | case <-time.After(10 * time.Second): |
| 200 | return errors.New("SSE ping data send timeout") |
| 201 | case <-c.Request.Context().Done(): |
| 202 | return errors.New("request context cancelled during ping") |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | func DoRequest(c *gin.Context, req *http.Request, info *common.RelayInfo) (*http.Response, error) { |
| 207 | return doRequest(c, req, info) |
no test coverage detected