From 55b4451ba16ba652050f2770dddc1a2738f24afd Mon Sep 17 00:00:00 2001 From: Xingcan LAN Date: Tue, 9 Jul 2019 10:55:17 +0800 Subject: [PATCH] Fix ConsumerGroup._checkTopicPartitionCheck Previous behavior only check topics that this consumer is subscribed, if two consumer with same group id subscribed to different topic, group master cannot check topic partition change correctly, and rejoin the whole group each time such check is scheduled. This is because this.topicPartitionLength is initialized when joining group and contains all the topics that has been subscribed by this group, while this.topics may not contains all the topics. In such condition: ``` const topicOrPartitionsChanged = _.some(this.topicPartitionLength, function (numberOfPartitions, topic) { return numberOfPartitions !== _.get(metadata, `['${topic}'].length`, 0); }); ``` So `topicPartitionChanged` will always be caculated to be true. --- lib/consumerGroup.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/consumerGroup.js b/lib/consumerGroup.js index 5b7d9c74..aa5b3c39 100644 --- a/lib/consumerGroup.js +++ b/lib/consumerGroup.js @@ -318,7 +318,8 @@ ConsumerGroup.prototype.scheduleTopicPartitionCheck = function () { }; ConsumerGroup.prototype._checkTopicPartitionChange = function (callback) { - this.client.loadMetadataForTopics(this.topics, (error, metadataResponse) => { + const topics = Object.keys(this.topicPartitionLength); + this.client.loadMetadataForTopics(topics, (error, metadataResponse) => { if (error) { return callback(error); }