[kafka_consumer] Fix consumer leak when offsets_for_times times out#23241
Open
piochelepiotr wants to merge 4 commits intomasterfrom
Open
[kafka_consumer] Fix consumer leak when offsets_for_times times out#23241piochelepiotr wants to merge 4 commits intomasterfrom
piochelepiotr wants to merge 4 commits intomasterfrom
Conversation
Wrap Consumer usage in get_watermark_offsets() in try/finally to ensure close_consumer() is always called, even when offsets_for_times() throws. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
get_watermark_offsets()— whenoffsets_for_times()throws (e.g., timeout),close_consumer()was skipped because the exception jumped over it. The consumer is now closed in afinallyblock.How the leak happens:
open_consumer()is called at line 410, but ifoffsets_for_times()at line 420 raises aKafkaException(timeout), execution jumps to the caller'sexceptblock, skippingclose_consumer(). On the next check run,open_consumer()overwritesself._consumerwith a new instance, and the old one is only cleaned up by GC.Test plan
close_consumer()is called even whenoffsets_for_times()throws by reviewing the try/finally structure🤖 Generated with Claude Code