Skip to content

[kafka_consumer] Fix consumer leak when offsets_for_times times out#23241

Open
piochelepiotr wants to merge 4 commits intomasterfrom
piotr.wolski/fix-consumer-leak-on-timeout
Open

[kafka_consumer] Fix consumer leak when offsets_for_times times out#23241
piochelepiotr wants to merge 4 commits intomasterfrom
piotr.wolski/fix-consumer-leak-on-timeout

Conversation

@piochelepiotr
Copy link
Copy Markdown
Contributor

@piochelepiotr piochelepiotr commented Apr 9, 2026

Summary

  • Fix a consumer leak in get_watermark_offsets() — when offsets_for_times() throws (e.g., timeout), close_consumer() was skipped because the exception jumped over it. The consumer is now closed in a finally block.

How the leak happens: open_consumer() is called at line 410, but if offsets_for_times() at line 420 raises a KafkaException (timeout), execution jumps to the caller's except block, skipping close_consumer(). On the next check run, open_consumer() overwrites self._consumer with a new instance, and the old one is only cleaned up by GC.

Test plan

  • Existing unit/integration tests pass
  • Verify close_consumer() is called even when offsets_for_times() throws by reviewing the try/finally structure

🤖 Generated with Claude Code

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>
piochelepiotr and others added 3 commits April 8, 2026 21:05
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
Copy link
Copy Markdown

codecov bot commented Apr 9, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.01%. Comparing base (0a22c2c) to head (0558c4e).

Additional details and impacted files
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant