From 411396b84fb5c417a9ffa20b8aefc8ad64646221 Mon Sep 17 00:00:00 2001 From: Shamil Ishraq Date: Mon, 20 Jan 2020 21:06:27 -0500 Subject: [PATCH] Randomize broker list for first_broker_response() so that metadata update requests don't always go to the same broker --- lib/kafka_ex/new/client.ex | 4 +++- lib/kafka_ex/server.ex | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/kafka_ex/new/client.ex b/lib/kafka_ex/new/client.ex index 638339e4..19cca6f9 100644 --- a/lib/kafka_ex/new/client.ex +++ b/lib/kafka_ex/new/client.ex @@ -442,7 +442,9 @@ defmodule KafkaEx.New.Client do end defp first_broker_response(request, brokers, timeout) do - Enum.find_value(brokers, fn broker -> + brokers + |> Enum.shuffle() + |> Enum.find_value(brokers, fn broker -> if Broker.connected?(broker) do try_broker(broker, request, timeout) end diff --git a/lib/kafka_ex/server.ex b/lib/kafka_ex/server.ex index 5612fbd8..abb9d087 100644 --- a/lib/kafka_ex/server.ex +++ b/lib/kafka_ex/server.ex @@ -974,7 +974,9 @@ defmodule KafkaEx.Server do end defp first_broker_response(request, brokers, timeout) do - Enum.find_value(brokers, fn broker -> + brokers + |> Enum.shuffle() + |> Enum.find_value(fn broker -> if Broker.connected?(broker) do # credo:disable-for-next-line Credo.Check.Refactor.Nesting case NetworkClient.send_sync_request(broker, request, timeout) do