diff --git a/internal/rpcserver/rpcwebsocket.go b/internal/rpcserver/rpcwebsocket.go index 3d2ccecced..b16d5d6e89 100644 --- a/internal/rpcserver/rpcwebsocket.go +++ b/internal/rpcserver/rpcwebsocket.go @@ -169,18 +169,15 @@ func (m *wsNotificationManager) queueHandler(ctx context.Context) { var dequeue chan<- interface{} skipQueue := m.notificationMsgs var next interface{} -out: + for { select { case <-ctx.Done(): - break out - - case n, ok := <-m.queueNotification: - if !ok { - // Sender closed input channel. - break out - } + close(m.notificationMsgs) + m.wg.Done() + return + case n := <-m.queueNotification: // Either send to out immediately if skipQueue is // non-nil (queue is empty) and reader is ready, // or append to the queue and send later. @@ -205,9 +202,6 @@ out: } } } - - close(m.notificationMsgs) - m.wg.Done() } // NotifyBlockConnected passes a block newly-connected to the best chain