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

Release readBuffer when close BufferedReadChannel & BufferedChannel #4030

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

Conversation

lifepuzzlefun
Copy link
Contributor

@lifepuzzlefun lifepuzzlefun commented Jul 15, 2023

Motivation

Release readBuffer when close BufferedReadChannel & BufferedChannel

BufferedChannel is subclass of BufferedReadChannel, which will create a readBuffer to cache read content.

When close BufferedChannel, the readBuffer should be released to avoid memory leak.

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 provide more context about this change?

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.

I support this change. Would you please add a test to cover this change? Especially cover the readBuffer leak case.

}

readBufferStartPosition = Long.MIN_VALUE;
readBuffer.release();
Copy link
Contributor

Choose a reason for hiding this comment

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

We'd better use ReferenceCountUtil.release(readBuffer); instead of readBuffer.release();

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, fixed.

Comment on lines +105 to +106
super.close();
writeBufferStartPosition.set(0);
Copy link
Member

Choose a reason for hiding this comment

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

Should we close and reset the position after setting the closed to true?

@@ -899,6 +899,7 @@ private BufferedReadChannel getChannelForLogId(long entryLogId) throws IOExcepti
// We set the position of the write buffer of this buffered channel to Long.MAX_VALUE
// so that there are no overlaps with the write buffer while reading
fc = new BufferedReadChannel(newFc, conf.getReadBufferBytes());

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change


// BufferedReadChannel is not response for fileChannel close.

closed = true;
Copy link
Member

Choose a reason for hiding this comment

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

Move the closed to the first step?

Copy link
Contributor

@dlg99 dlg99 left a comment

Choose a reason for hiding this comment

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

In general LGTM, but needs a test and more context on scenarios when this is a problem

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

Successfully merging this pull request may close these issues.

8 participants