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

RATIS-1278. Resource leak when decoding DataStreamReplyByteBuffer. #388

Merged
merged 1 commit into from Dec 31, 2020
Merged

RATIS-1278. Resource leak when decoding DataStreamReplyByteBuffer. #388

merged 1 commit into from Dec 31, 2020

Conversation

szetszwo
Copy link
Contributor

@szetszwo szetszwo closed this Dec 30, 2020
@szetszwo szetszwo reopened this Dec 30, 2020
@szetszwo szetszwo closed this Dec 30, 2020
@szetszwo szetszwo reopened this Dec 30, 2020
@szetszwo szetszwo closed this Dec 30, 2020
@szetszwo szetszwo reopened this Dec 30, 2020
@runzhiwang runzhiwang closed this Dec 30, 2020
@runzhiwang runzhiwang reopened this Dec 30, 2020
@runzhiwang
Copy link
Contributor

@szetszwo Hi, I have test this PR, it does work. Could you help explain the root cause of the problem ?

@runzhiwang runzhiwang closed this Dec 31, 2020
@runzhiwang runzhiwang reopened this Dec 31, 2020
@runzhiwang runzhiwang closed this Dec 31, 2020
@runzhiwang runzhiwang reopened this Dec 31, 2020
@szetszwo
Copy link
Contributor Author

@runzhiwang , thanks a lot for testing it.

-            .setBuffer(decodeData(buf, header, b -> b.copy().nioBuffer()))
+            .setBuffer(decodeData(buf, header, NettyDataStreamUtils::copy))

The original code uses Netty ByteBuf.copy(). It allocates a ByteBuf object from its buffer pool and the object needs to be released afterward. Otherwise, there is a leak.

The new code copies the ByteBuf by creating a new byte[]. Of course, Java will gc it afterward as usual.

Copy link
Contributor

@runzhiwang runzhiwang left a comment

Choose a reason for hiding this comment

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

LGTM

@runzhiwang runzhiwang closed this Dec 31, 2020
@runzhiwang runzhiwang reopened this Dec 31, 2020
@runzhiwang runzhiwang closed this Dec 31, 2020
@runzhiwang runzhiwang reopened this Dec 31, 2020
@runzhiwang runzhiwang merged commit b6fbb50 into apache:master Dec 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants