From d759d7c365786c68aea976f0965835e84b2fad59 Mon Sep 17 00:00:00 2001 From: Chris Rivera Date: Tue, 9 Jun 2020 13:11:38 -0500 Subject: [PATCH] Fix the error handling in client.InitProducerID() err was shadowed in InitProducerID() so it would never return a non-nil error. It now returns ErrOutOfBrokers if there aren't any registered brokers. If there are registered brokers and the broker calls fail then it returns the last encoutered error. This was causing a panic in newTransactionManager() with idempotent production enabled because nil, nil was being returned if the brokers were unavailable. --- client.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/client.go b/client.go index c3392f961e..5a7d1338cc 100644 --- a/client.go +++ b/client.go @@ -197,11 +197,12 @@ func (client *client) Brokers() []*Broker { } func (client *client) InitProducerID() (*InitProducerIDResponse, error) { - var err error + err := ErrOutOfBrokers for broker := client.any(); broker != nil; broker = client.any() { + var response *InitProducerIDResponse req := &InitProducerIDRequest{} - response, err := broker.InitProducerID(req) + response, err = broker.InitProducerID(req) switch err.(type) { case nil: return response, nil @@ -212,6 +213,7 @@ func (client *client) InitProducerID() (*InitProducerIDResponse, error) { client.deregisterBroker(broker) } } + return nil, err }