Skip to content

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.

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