[#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 <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2020-10-13 18:36:13 +03:00 committed by Alex Vanin
parent d3d8f00757
commit ca006245d2

View file

@ -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)