fix(httpapi): detect ws client disconnect via CloseRead to prevent subscriber leak

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MMHQTtnQtQqL8muAXHr9kd
This commit is contained in:
2026-07-01 18:47:54 +07:00
parent 9ec6acd414
commit 4c57848c35
3 changed files with 74 additions and 1 deletions
+4 -1
View File
@@ -25,7 +25,10 @@ func (s *Server) handleWS(w http.ResponseWriter, r *http.Request) {
subID, ch := s.hub.Subscribe(taskID)
defer s.hub.Unsubscribe(taskID, subID)
ctx := r.Context()
// websocket.Accept хайджекает соединение, поэтому r.Context() не отменяется
// при обрыве связи клиентом. CloseRead запускает фоновое чтение control-фреймов
// и отменяет возвращаемый контекст, когда соединение действительно умирает.
ctx := c.CloseRead(r.Context())
for {
select {
case ev, ok := <-ch: