From ca006245d257f8d589fbd3dacb53ded7704f95dc Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Tue, 13 Oct 2020 18:36:13 +0300 Subject: [PATCH] [#72] Close subscription channel if RPC was terminated RPC node closes websocket notification channel if it was terminated or something wrong happened. Subscriber has to check this condition and alert about this in upper context by closing it's own channel. Signed-off-by: Alex Vanin --- pkg/morph/subscriber/subscriber.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pkg/morph/subscriber/subscriber.go b/pkg/morph/subscriber/subscriber.go index c52d4a34..7a186514 100644 --- a/pkg/morph/subscriber/subscriber.go +++ b/pkg/morph/subscriber/subscriber.go @@ -104,7 +104,14 @@ func (s *subscriber) routeNotifications(ctx context.Context) { select { case <-ctx.Done(): return - case notification := <-s.client.Notifications: + case notification, ok := <-s.client.Notifications: + if !ok { + s.log.Warn("remote channel has been closed") + close(s.notify) + + return + } + switch notification.Type { case response.NotificationEventID: notification, ok := notification.Value.(*result.NotificationEvent)