-
Notifications
You must be signed in to change notification settings - Fork 903
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
base: master
Are you sure you want to change the base?
Conversation
DefaultEntryLogger.scanEntryLog
DefaultEntryLogger.scanEntryLog
There was a problem hiding this 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.
+1 |
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; |
There was a problem hiding this comment.
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);
}
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree with @AnonHxy
There was a problem hiding this 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.
it should be released