From d5d886d853bac16ba0ca29a655a92f796711c9b0 Mon Sep 17 00:00:00 2001 From: vyzo Date: Tue, 6 Mar 2018 11:50:16 +0200 Subject: [PATCH 1/2] Don't block the event loop if the subscriber is too slow Closes #69 --- pubsub.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pubsub.go b/pubsub.go index d607cc5..8943e52 100644 --- a/pubsub.go +++ b/pubsub.go @@ -326,7 +326,11 @@ func (p *PubSub) notifySubs(msg *pb.Message) { for _, topic := range msg.GetTopicIDs() { subs := p.myTopics[topic] for f := range subs { - f.ch <- &Message{msg} + select { + case f.ch <- &Message{msg}: + default: + log.Errorf("Can't deliver message to subscription for topic %s; subscriber too slow", topic) + } } } } From 1538e0d417c5d67aa4eb02dba09e87561dc881d7 Mon Sep 17 00:00:00 2001 From: vyzo Date: Tue, 6 Mar 2018 12:11:06 +0200 Subject: [PATCH 2/2] downgrade dropped message logging to Infof --- pubsub.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubsub.go b/pubsub.go index 8943e52..a4f68a7 100644 --- a/pubsub.go +++ b/pubsub.go @@ -329,7 +329,7 @@ func (p *PubSub) notifySubs(msg *pb.Message) { select { case f.ch <- &Message{msg}: default: - log.Errorf("Can't deliver message to subscription for topic %s; subscriber too slow", topic) + log.Infof("Can't deliver message to subscription for topic %s; subscriber too slow", topic) } } }