Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix headerBuffer leak in DefaultEntryLogger.scanEntryLog #4023

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

lifepuzzlefun
Copy link
Contributor

it should be released

@lifepuzzlefun lifepuzzlefun changed the title Fix headerBuffer not released in DefaultEntryLogger.scanEntryLog Fix headerBuffer leak in DefaultEntryLogger.scanEntryLog Jul 8, 2023
Copy link
Member

@horizonzy horizonzy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also release the headerBuffer when getChannelForLogId throw exception.

@hangc0276
Copy link
Contributor

We should also release the headerBuffer when getChannelForLogId throw exception.

+1

@lifepuzzlefun
Copy link
Contributor Author

Nice suggestion! The change has been committed.

// Get the BufferedChannel for the current entry log file
try {
bc = getChannelForLogId(entryLogId);
} catch (IOException e) {
LOG.warn("Failed to get channel to scan entry log: " + entryLogId + ".log");
throwExceptionWhenGetChannel = true;
Copy link
Contributor

@AnonHxy AnonHxy Jul 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not call headerBuffer.release() here?

And I think that it will be better if we move line969 to just before the second try catch block, like:

ByteBuf data = allocator.directBuffer(1024 * 1024);
ByteBuf headerBuffer = Unpooled.buffer(4 + 8);  // line969
 try {
           
            // Read through the entry log file and extract the ledger ID's.
            while (true) {
                // Check if we'`
            // ...
           // ...
 finally {
           ReferenceCountUtil.release(headerBuffer);
            ReferenceCountUtil.release(data);
   }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for review. I think the code function is the same. release resource in finally code block is more like the java style.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree with @AnonHxy

Copy link
Contributor

@hangc0276 hangc0276 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you please add a test to cover this change? thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants