From a1817eb6ae2e005340f1a8a141e38784c6d3bf6e Mon Sep 17 00:00:00 2001 From: Yasss Date: Wed, 12 Jun 2019 17:51:06 +0200 Subject: [PATCH 1/2] Fix panicking --- consumer/consumer.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/consumer/consumer.go b/consumer/consumer.go index 0187f43..c4d7c09 100644 --- a/consumer/consumer.go +++ b/consumer/consumer.go @@ -81,7 +81,7 @@ func (c *Consumer) setup() { } } - if c.retryStrategy == nil { + if c.config != nil && c.retryStrategy == nil { // Note: the logic in handleMsg assumes that // this does not terminate; be aware of that when changing // this strategy. @@ -101,14 +101,14 @@ func (c *Consumer) setup() { // When Serve terminates it will return an Error or nil to indicate // that it excited without error. func (c *Consumer) Serve(config Config, addrs ...string) error { - c.setup() - c.config = &config err := c.validateConfig() if err != nil { return err } + c.setup() + topics := c.handlers.Topics() consumerGroup := fmt.Sprintf("%s-consumer-group", c.config.ClientID) From 3327d2ba24d4bad5bba659eb5df06ce0ed93f2bf Mon Sep 17 00:00:00 2001 From: Yasss Date: Wed, 12 Jun 2019 18:11:13 +0200 Subject: [PATCH 2/2] Remove unreachable panic --- consumer/consumer.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/consumer/consumer.go b/consumer/consumer.go index c4d7c09..a8e23cc 100644 --- a/consumer/consumer.go +++ b/consumer/consumer.go @@ -239,7 +239,8 @@ func (c *Consumer) handleMsg(msg *sarama.ConsumerMessage) (*Message, int) { } return m, attempts } - panic("unreachable") + return nil, attempts + } // MetricsReporter is an interface that can be passed to set metrics hook to receive metrics