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:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user