fix: resource leak when JournalChannel is not fully initialized #4340
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.
Motivation
There is a resource leak in the
JournalChannel
implementation of Apache Bookkeeper when the channel is closed before it is fully initialized (specifically, before the writing of headers begins). In such cases, the buffer channel (bc
) is not yet instantiated, but the file channel (fc
) might already be open.Changes
Updated the
close()
method inJournalChannel
to include a conditional check that closes the file channel (fc
) if the buffer channel (bc
) is null. This ensures that all resources are properly released, even if theJournalChannel
is prematurely closed before full initialization.wrie header method
bookkeeper/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/JournalChannel.java
Lines 250 to 265 in ba7f988