Browse Source

If we think the broker is dead, check we can connect

This might help with part of #151 by triggering the WaitForElection timeout if
we're super-eager and request metadata before the cluster even realizes the
broker is gone.
Evan Huus 11 years ago
parent
commit
c4e1e3344b
1 changed files with 8 additions and 0 deletions
  1. 8 0
      client.go

+ 8 - 0
client.go

@@ -441,6 +441,14 @@ func (client *Client) update(data *MetadataResponse) ([]string, error) {
 				toRetry[topic.Name] = true
 				delete(client.leaders[topic.Name], partition.ID)
 			case NoError:
+				broker := client.brokers[partition.Leader]
+				if _, present := client.deadBrokerAddrs[broker.Addr()]; present {
+					if connected, _ := broker.Connected(); !connected {
+						toRetry[topic.Name] = true
+						delete(client.leaders[topic.Name], partition.ID)
+						continue
+					}
+				}
 				client.leaders[topic.Name][partition.ID] = partition.Leader
 			default:
 				return nil, partition.Err