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 memory leak when reading entry but the connection disconnected. #3528

Merged
merged 7 commits into from
Oct 18, 2022

Conversation

horizonzy
Copy link
Member

Descriptions of the changes in this PR:
Fixes-#3527

@@ -145,12 +152,12 @@ protected void sendResponseAndWait(int rc, Object response, OpStatsLogger statsL
try {
ChannelFuture future = channel.writeAndFlush(response);
if (!channel.eventLoop().inEventLoop()) {
future.await();
Copy link
Contributor

Choose a reason for hiding this comment

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

what's the difference in this case ?

Copy link
Contributor

Choose a reason for hiding this comment

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

await() won't throw the exception out. We'd better catch the exception and log it in debug mode to help debug issues.

void retain() {
}

void release() {
Copy link
Contributor

Choose a reason for hiding this comment

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

what about keeping boolean release()
IIUC your problem is about implementing ReferenceCounted

Copy link
Contributor

Choose a reason for hiding this comment

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

It has conflict with the release() interface in ReferenceCounted

Copy link
Member

Choose a reason for hiding this comment

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

Yeah. I think we can keep boolean release(). Because ReferenceCounted also has the same method.

Copy link
Member Author

Choose a reason for hiding this comment

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

👍

@@ -445,7 +443,7 @@ void recycle() {
/**
* A request that reads data.
*/
class ReadResponse extends Response {
class ReadResponse extends Response implements ReferenceCounted {
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we need to implement ReferenceCounted ?
can you add a comment in the JavaDoc ?

Copy link
Contributor

Choose a reason for hiding this comment

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

#3527 will give more context.

@hangc0276
Copy link
Contributor

@horizonzy Great Catch!
There are some tests that failed, please help take a look.
https://github.com/apache/bookkeeper/actions/runs/3242629439/jobs/5316169295

channel.writeAndFlush(response, channel.voidPromise());
ChannelPromise promise = channel.newPromise().addListener(future -> {
if (!future.isSuccess()) {
logger.debug("Netty channel write exception. ", future.cause());
Copy link
Member

Choose a reason for hiding this comment

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

Why not log it as an error?

Copy link
Member Author

Choose a reason for hiding this comment

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

When this error occurs, it means that the client has already close. Log error is unnecessary, the other log will show the connection already close.

Copy link
Member

Choose a reason for hiding this comment

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

I think this need to print the error
logger.error("Netty channel write exception. ", future.cause());

void retain() {
}

void release() {
Copy link
Member

Choose a reason for hiding this comment

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

Yeah. I think we can keep boolean release(). Because ReferenceCounted also has the same method.

Copy link
Member

@michaeljmarshall michaeljmarshall left a comment

Choose a reason for hiding this comment

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

LGTM

@hangc0276
Copy link
Contributor

rerun failure checks

@wolfstudy
Copy link
Member

ping @eolivelli PTAL again, thanks

Copy link
Contributor

@eolivelli eolivelli left a comment

Choose a reason for hiding this comment

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

LGTM

@eolivelli
Copy link
Contributor

@StevenLuMT @zymap do you have other comments ?

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.

Nicely done.

Copy link
Member

@zymap zymap left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@StevenLuMT StevenLuMT left a comment

Choose a reason for hiding this comment

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

LGTM

@StevenLuMT StevenLuMT merged commit 30bdedc into apache:master Oct 18, 2022
zymap pushed a commit that referenced this pull request Oct 26, 2022
…3528)

* Fix direct memory leak problem

(cherry picked from commit 30bdedc)
hangc0276 pushed a commit to hangc0276/bookkeeper that referenced this pull request Nov 7, 2022
…pache#3528)

* Fix direct memory leak problem

(cherry picked from commit 30bdedc)
hangc0276 pushed a commit to hangc0276/bookkeeper that referenced this pull request Nov 7, 2022
…pache#3528)

* Fix direct memory leak problem

(cherry picked from commit 30bdedc)
nicoloboschi pushed a commit to datastax/bookkeeper that referenced this pull request Jan 11, 2023
…pache#3528)

* Fix direct memory leak problem

(cherry picked from commit 30bdedc)
(cherry picked from commit 9329e3c)
nicoloboschi added a commit to datastax/bookkeeper that referenced this pull request Jan 20, 2023
Comment on lines +124 to +128
ChannelPromise promise = channel.newPromise().addListener(future -> {
if (!future.isSuccess()) {
logger.debug("Netty channel write exception. ", future.cause());
}
});
Copy link
Member

Choose a reason for hiding this comment

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

This will cause unnecessary object creation. If the only purpose is to log exceptions, channel.voidPromise() already takes care of that.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for reminder.

Copy link
Contributor

Choose a reason for hiding this comment

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

It has been fixed here: #3733

nicoloboschi pushed a commit to datastax/bookkeeper that referenced this pull request Mar 13, 2023
…pache#3528)

* Fix direct memory leak problem

(cherry picked from commit 30bdedc)
(cherry picked from commit 9329e3c)
nicoloboschi pushed a commit to datastax/bookkeeper that referenced this pull request Mar 13, 2023
…pache#3528)

* Fix direct memory leak problem

(cherry picked from commit 30bdedc)
(cherry picked from commit 9329e3c)
Ghatage pushed a commit to sijie/bookkeeper that referenced this pull request Jul 12, 2024
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.