Fix websocket issue

pull/600/head
binwiederhier 2023-01-24 14:44:14 -05:00
parent 38a1193523
commit a278297f28
1 changed files with 5 additions and 7 deletions

View File

@ -1035,13 +1035,7 @@ func (s *Server) handleSubscribeWS(w http.ResponseWriter, r *http.Request, v *vi
// Use errgroup to run WebSocket reader and writer in Go routines
var wlock sync.Mutex
g, gctx := errgroup.WithContext(context.Background())
g.Go(func() error {
<-subscriberContext.Done()
log.Trace("%s Cancel received, closing subscriber connection", logHTTPPrefix(v, r))
conn.Close()
return &websocket.CloseError{Code: websocket.CloseNormalClosure, Text: "subscription was canceled"}
})
g, gctx := errgroup.WithContext(subscriberContext)
g.Go(func() error {
pongWait := s.config.KeepaliveInterval + wsPongWait
conn.SetReadLimit(wsReadLimit)
@ -1078,6 +1072,10 @@ func (s *Server) handleSubscribeWS(w http.ResponseWriter, r *http.Request, v *vi
select {
case <-gctx.Done():
return nil
case <-subscriberContext.Done():
log.Trace("%s Cancel received, closing subscriber connection", logHTTPPrefix(v, r))
conn.Close()
return &websocket.CloseError{Code: websocket.CloseNormalClosure, Text: "subscription was canceled"}
case <-time.After(s.config.KeepaliveInterval):
v.Keepalive()
if err := ping(); err != nil {