Skip to content

Commit

Permalink
Fix the error handling in client.InitProducerID()
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
crivera-fastly committed Apr 2, 2021
1 parent 41df78d commit af35301
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,12 @@ func (client *client) Broker(brokerID int32) (*Broker, error) {
}

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
Expand All @@ -228,6 +229,7 @@ func (client *client) InitProducerID() (*InitProducerIDResponse, error) {
client.deregisterBroker(broker)
}
}

return nil, err
}

Expand Down

0 comments on commit af35301

Please sign in to comment.