You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "Kamal Chandraprakash (Jira)" <ji...@apache.org> on 2026/02/11 10:48:00 UTC
[jira] [Resolved] (KAFKA-19874) Fix resource leak in TopicBasedRemoteLogMetadataManager initialization
[ https://issues.apache.org/jira/browse/KAFKA-19874?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Kamal Chandraprakash resolved KAFKA-19874.
------------------------------------------
Resolution: Invalid
> Fix resource leak in TopicBasedRemoteLogMetadataManager initialization
> ----------------------------------------------------------------------
>
> Key: KAFKA-19874
> URL: https://issues.apache.org/jira/browse/KAFKA-19874
> Project: Kafka
> Issue Type: Bug
> Components: core
> Affects Versions: 4.1.0
> Reporter: lightzhao
> Priority: Major
>
> ## Problem
> There is a resource leak in the TopicBasedRemoteLogMetadataManager initialization
> process. If ProducerManager is created successfully but ConsumerManager creation
> fails, the ProducerManager instance is not properly closed, leading to resource
> leaks (e.g., unclosed Kafka producer, threads, network connections).
> ## Current Code (Problematic)
> lock.writeLock().lock();
> try {
> producerManager = new ProducerManager(rlmmConfig, partitioner);
> consumerManager = new ConsumerManager(rlmmConfig, remotePartitionMetadataStore, partitioner, time);
> consumerManager.startConsumerThread();
> // If exception occurs here, producerManager is not closed
> } catch (Exception e) {
> log.error("Encountered error while initializing producer/consumer", e);
> initializationFailed = true;
> } finally {
> lock.writeLock().unlock();
> }## Solution
> Use temporary variables to hold manager instances and only assign to instance
> variables after successful initialization. Clean up temporary resources in the
> catch block if any exception occurs.
> ## Impact
> - Prevents resource leaks during initialization failures
> - Ensures proper cleanup of Kafka clients
> - Improves system stability and resource management
--
This message was sent by Atlassian Jira
(v8.20.10#820010)