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 Jun 9, 2020
1 parent 0189d59 commit d759d7c
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 @@ -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
Expand All @@ -212,6 +213,7 @@ func (client *client) InitProducerID() (*InitProducerIDResponse, error) {
client.deregisterBroker(broker)
}
}

return nil, err
}

Expand Down

0 comments on commit d759d7c

Please sign in to comment.