From 0f6caf9b1df756e6c7db9a83ca34e4fe7a1a7197 Mon Sep 17 00:00:00 2001 From: abicky Date: Wed, 25 Mar 2020 05:41:47 +0900 Subject: [PATCH] Disconnect after leaving the group This commit removes an unnecessary reconnection after `Kafka::Consumer#stop` is called. `@cluster.disconnect` closes the connections to all brokers including the coordinator in spite of the fact that `@group.leave` requires a connection to the coordinator, so call `@cluster.disconnect` after `@group.leave`. --- lib/kafka/consumer.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/kafka/consumer.rb b/lib/kafka/consumer.rb index 6ddbaf798..d7deb8978 100644 --- a/lib/kafka/consumer.rb +++ b/lib/kafka/consumer.rb @@ -116,7 +116,6 @@ def subscribe(topic_or_regex, default_offset: nil, start_from_beginning: true, m def stop @running = false @fetcher.stop - @cluster.disconnect end # Pause processing of a specific topic partition. @@ -433,6 +432,7 @@ def consumer_loop # important that members explicitly tell Kafka when they're leaving. make_final_offsets_commit! @group.leave rescue nil + @cluster.disconnect @running = false @logger.pop_tags end