lightzhao opened a new pull request, #20849:
URL: https://github.com/apache/kafka/pull/20849
## 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 is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]