diff --git a/server/web/ws.go b/server/web/ws.go index 01c97da..bfccd49 100644 --- a/server/web/ws.go +++ b/server/web/ws.go @@ -64,17 +64,16 @@ func (t *WS) ServeHTTP(resp http.ResponseWriter, req *http.Request) { t.channels[id] = ch t.mutex.Unlock() - defer func() { - t.mutex.Lock() - delete(t.channels, id) - close(ch) - t.mutex.Unlock() - }() - for { - data := <-ch - conn.WriteMessage(websocket.TextMessage, data) + err := conn.WriteMessage(websocket.TextMessage, data) + if err != nil { + break + } } + t.mutex.Lock() + delete(t.channels, id) + close(ch) + t.mutex.Unlock() }