[#324] morph/listener: Prevent potential writing to nil channel

Write error returned by BlockNotifications() call ins listenLoop method body
to error channel only if it is procided. Otherwise, write debug log message.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-01-25 14:57:44 +03:00 committed by Alex Vanin
parent 96febdb6a5
commit 5e212f97d6

View file

@ -155,7 +155,13 @@ func (s listener) listen(ctx context.Context, intError chan<- error) error {
func (s listener) listenLoop(ctx context.Context, chEvent <-chan *state.NotificationEvent, intErr chan<- error) {
blockChan, err := s.subscriber.BlockNotifications()
if err != nil {
if intErr != nil {
intErr <- errors.Wrap(err, "could not open block notifications channel")
} else {
s.log.Debug("could not open block notifications channel",
zap.String("error", err.Error()),
)
}
return
}