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

LEAK: ByteBuf.release() was not called, 1.63.0 #11115

Closed
y-kawawa opened this issue Apr 19, 2024 · 2 comments
Closed

LEAK: ByteBuf.release() was not called, 1.63.0 #11115

y-kawawa opened this issue Apr 19, 2024 · 2 comments
Labels
Milestone

Comments

@y-kawawa
Copy link

y-kawawa commented Apr 19, 2024

What version of gRPC-Java are you using?

1.63.0

This issue does not occur in version 1.62.2.

What is your environment?

  • Linux
  • Java11

What did you expect to see?

ByteBuf is released

What did you see instead?

LEAK: ByteBuf.release() was not called before it's garbage-collected.

Steps to reproduce the bug

I am implementing a server-streaming RPC using grpc-java with the following behavior:

  • The server delivers content in response to client requests and continues until disconnected.
  • The server may also initiate disconnections.
  • This behavior is implemented for multiple clients simultaneously.

After the server has been running for a while, the following error occurs:

LEAK: ByteBuf.release() was not called before it's garbage-collected. See https://netty.io/wiki/reference-counted-objects.html for more information.
Recent access records: 
Created at:
	io.grpc.netty.shaded.io.netty.buffer.PooledByteBufAllocator.newDirectBuffer(PooledByteBufAllocator.java:402)
	io.grpc.netty.shaded.io.netty.buffer.AbstractByteBufAllocator.directBuffer(AbstractByteBufAllocator.java:188)
	io.grpc.netty.shaded.io.netty.buffer.AbstractByteBufAllocator.buffer(AbstractByteBufAllocator.java:124)
	io.grpc.netty.shaded.io.grpc.netty.NettyWritableBufferAllocator.allocate(NettyWritableBufferAllocator.java:51)
	io.grpc.internal.MessageFramer.writeKnownLengthUncompressed(MessageFramer.java:226)
	io.grpc.internal.MessageFramer.writeUncompressed(MessageFramer.java:172)
	io.grpc.internal.MessageFramer.writePayload(MessageFramer.java:143)
	io.grpc.internal.AbstractStream.writeMessage(AbstractStream.java:66)
	io.grpc.internal.ServerCallImpl.sendMessageInternal(ServerCallImpl.java:168)
	io.grpc.internal.ServerCallImpl.sendMessage(ServerCallImpl.java:152)
	io.grpc.stub.ServerCalls$ServerCallStreamObserverImpl.onNext(ServerCalls.java:380)
	com.example.Streaming.lambda$Process$0(Streaming.java:100)
	java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	java.base/java.lang.Thread.run(Thread.java:829)

Speculation

The changes in version 1.63.0 include #10258, which involves modifications in how stream resets are handled. This warning seems to occur in my environment particularly when the client closes the connection first, which may suggest a relationship to these changes.

I suspect the issue may be linked to the handling of closed connections and would appreciate further investigation into whether the changes in PR #10258 could be causing unintended side-effects in byte buffer management.

Others

There is a similar issue reported here: #11084, but it involves a different version and the stack trace is different, so I believe it might be a separate issue.

benjaminp added a commit to benjaminp/grpc-java that referenced this issue Apr 19, 2024
`sendGrpcFrame` owns the buffer in `SendGrpcFrameCommand`. If the frame is not handed off to netty, it needs to be released in the method.

grpc#11115
@ejona86 ejona86 added the bug label Apr 22, 2024
@ejona86 ejona86 added this to the 1.64 milestone Apr 22, 2024
larry-safran pushed a commit that referenced this issue Apr 22, 2024
`sendGrpcFrame` owns the buffer in `SendGrpcFrameCommand`. If the frame is not handed off to netty, it needs to be released in the method.

#11115
@ejona86
Copy link
Member

ejona86 commented Apr 23, 2024

Fixed by #11116

@ejona86 ejona86 closed this as completed Apr 23, 2024
ejona86 pushed a commit to ejona86/grpc-java that referenced this issue Apr 23, 2024
`sendGrpcFrame` owns the buffer in `SendGrpcFrameCommand`. If the frame is not handed off to netty, it needs to be released in the method.

grpc#11115
ejona86 pushed a commit that referenced this issue Apr 25, 2024
`sendGrpcFrame` owns the buffer in `SendGrpcFrameCommand`. If the frame is not handed off to netty, it needs to be released in the method.

#11115
@sergiitk
Copy link
Member

Note: the issue is fixed in v1.64.0, and the fix was backported to v1.63.1.

@sergiitk sergiitk reopened this May 21, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 20, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants