From 5e212f97d66f51c86ac76a9ae2139ed577019151 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Mon, 25 Jan 2021 14:57:44 +0300 Subject: [PATCH] [#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 --- pkg/morph/event/listener.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pkg/morph/event/listener.go b/pkg/morph/event/listener.go index 2f6f8da6..833c6558 100644 --- a/pkg/morph/event/listener.go +++ b/pkg/morph/event/listener.go @@ -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 { - intErr <- errors.Wrap(err, "could not open block notifications channel") + 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 }