Skip to content

Conversation

@lightzhao
Copy link

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

…initialization

This commit fixes a resource leak where ProducerManager would not be
properly closed if ConsumerManager initialization failed. The fix uses
temporary variables to hold the manager instances and only assigns them
to the instance variables after successful initialization. If any
exception occurs during initialization, the temporary instances are
properly closed using Utils.closeQuietly().

Changes:
- Introduced temporary variables for ProducerManager and ConsumerManager
- Only assign to instance variables after full successful initialization
- Added cleanup of temporary resources in the catch block
- Added descriptive comments explaining the initialization flow
@github-actions github-actions bot added triage PRs from the community storage Pull requests that target the storage module tiered-storage Related to the Tiered Storage feature small Small PRs labels Nov 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-approved small Small PRs storage Pull requests that target the storage module tiered-storage Related to the Tiered Storage feature triage PRs from the community

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants