Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions kafka_consumer/changelog.d/23241.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix consumer leak when offsets_for_times() times out, preventing a potential librdkafka crash
27 changes: 14 additions & 13 deletions kafka_consumer/datadog_checks/kafka_consumer/kafka_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,21 +408,22 @@ def get_watermark_offsets(self, partitions=None, mode=HIGH_WATERMARK):

# Open consumer once for both cluster_id and offset fetching
self.client.open_consumer(dd_consumer_group)
cluster_id, _ = self.client.consumer_get_cluster_id_and_list_topics(dd_consumer_group)

self.log.debug(
'Querying %s %s offsets',
len(topic_partitions_to_check),
'highwater' if mode == HIGH_WATERMARK else 'lowwater',
)
try:
cluster_id, _ = self.client.consumer_get_cluster_id_and_list_topics(dd_consumer_group)

result = {}
for topic, partition, offset in self.client.consumer_offsets_for_times(
partitions=topic_partitions_to_check, offset=mode
):
result[(topic, partition)] = offset
self.log.debug(
'Querying %s %s offsets',
len(topic_partitions_to_check),
'highwater' if mode == HIGH_WATERMARK else 'lowwater',
)

self.client.close_consumer()
result = {}
for topic, partition, offset in self.client.consumer_offsets_for_times(
partitions=topic_partitions_to_check, offset=mode
):
result[(topic, partition)] = offset
finally:
self.client.close_consumer()

self.log.debug('Got %s %s offsets', len(result), 'highwater' if mode == HIGH_WATERMARK else 'lowwater')
return result, cluster_id
Expand Down
Loading