Fix websocket issue
This commit is contained in:
parent
38a1193523
commit
a278297f28
1 changed files with 5 additions and 7 deletions
|
@ -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
|
// Use errgroup to run WebSocket reader and writer in Go routines
|
||||||
var wlock sync.Mutex
|
var wlock sync.Mutex
|
||||||
g, gctx := errgroup.WithContext(context.Background())
|
g, gctx := errgroup.WithContext(subscriberContext)
|
||||||
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.Go(func() error {
|
g.Go(func() error {
|
||||||
pongWait := s.config.KeepaliveInterval + wsPongWait
|
pongWait := s.config.KeepaliveInterval + wsPongWait
|
||||||
conn.SetReadLimit(wsReadLimit)
|
conn.SetReadLimit(wsReadLimit)
|
||||||
|
@ -1078,6 +1072,10 @@ func (s *Server) handleSubscribeWS(w http.ResponseWriter, r *http.Request, v *vi
|
||||||
select {
|
select {
|
||||||
case <-gctx.Done():
|
case <-gctx.Done():
|
||||||
return nil
|
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):
|
case <-time.After(s.config.KeepaliveInterval):
|
||||||
v.Keepalive()
|
v.Keepalive()
|
||||||
if err := ping(); err != nil {
|
if err := ping(); err != nil {
|
||||||
|
|
Loading…
Reference in a new issue