title: Infinite rebalancing of consumer group with kafka and python-kafka library?
body: <p>I am using docker swarm to deploy 1 zookeeper and 3 brokers. I have two groups on there where my consumer applications are being replicated with a specific group to join. </p>
  
  <p>With the groups I am encountering a problem. When there is one consumer for a particular group and topic, there is not an issue. However, when I replicate the consumers to be greater than one for a consumer group, it seems that either one consumer gets all the partitions and there is never an even spread given the implemented partitioning algorithm and in addition to that, the main problem is that there is an infinite rebalancing of the group. </p>
  
  <p>The generations reach into the hundreds and thousands if I don't restart the kafka server. </p>
  
  <p>In my kafka config (properties.server) I have:
      my group.max.session.timeout.ms = 300000</p>
  
  <p>in my consumer code I am using kafka-python:
  consumer instantializes with the following config: </p>
  
  <pre class="lang-py prettyprint-override"><code>   self.kafka_server = KafkaConsumer(
                  group_id=self.kafka_topic,
                  bootstrap_servers=self.kafka_brokers,
                  enable_auto_commit=True,
                  value_deserializer=lambda x: json.loads(x),
                  api_version=(0, 10),
                  session_timeout_ms=300000,
                  heartbeat_interval_ms=100000,
                  max_poll_interval_ms=300000,
                  partition_assignment_strategy=[RoundRobinPartitionAssignor, RangePartitionAssignor]
              )
              sleep(10)
              self.kafka_server.subscribe(topics=self.kafka_topic)
  </code></pre>
  
  <p>My code for polling is:</p>
  
  <pre class="lang-py prettyprint-override"><code>  try:
              while True:
                  fetch_from_all_partitions = self.kafka_server.poll(timeout_ms=3000, max_records=20)
  </code></pre>
  
  <p>The consumer is being contacted correctly and is reaching the brokers. However, the consumer logs show no issue. The kafka logs show now issue either and it seems the group coordinator just continues to attempt to rebalance infinitely.</p>
  
  <p>Thanks</p>
  
  <p>Here is the log output:</p>
  
  <pre><code>[2019-08-13 18:47:20,294] INFO [GroupCoordinator 2]: Preparing to rebalance group group_name in state PreparingRebalance with old generation 124 (__consumer_offsets-22) (reason: Adding new member kafka-python-1.4.6-e2ea4ede-b28a-4ff1-a986-ef42efe9101a with group instanceid None) (kafka.coordinator.group.GroupCoordinator)
  
  [2019-08-13 18:47:20,295] INFO [GroupCoordinator 2]: Stabilized group group_name generation 125 (__consumer_offsets-22) (kafka.coordinator.group.GroupCoordinator)
  
  [2019-08-13 18:47:20,296] INFO [GroupCoordinator 2]: Assignment received from leader for group group_name for generation 125 (kafka.coordinator.group.GroupCoordinator)
  </code></pre>
  
  <p>This is infinite repeat.</p>