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 before it's garbage-collected. #11910

Open
li-zoe-x opened this issue Feb 19, 2025 · 3 comments
Open

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

li-zoe-x opened this issue Feb 19, 2025 · 3 comments

Comments

@li-zoe-x
Copy link

What version of gRPC-Java are you using?

1.70.0

What is your environment?

linux
jdk 17

What did you expect to see?

no leak

What did you see instead?

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

Steps to reproduce the bug

my log:
i.n.u.ResourceLeakDetector : 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.netty.buffer.PooledByteBufAllocator.newDirectBuffer(PooledByteBufAllocator.java:404)
io.netty.buffer.AbstractByteBufAllocator.directBuffer(AbstractByteBufAllocator.java:188)
io.netty.buffer.AbstractByteBufAllocator.buffer(AbstractByteBufAllocator.java:124)
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:70)
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)

@kannanjgithub
Copy link
Contributor

This is most likely caused by multiple server threads writing to the same StreamObserver without synchronization that causes mismatch with Netty reference counting.

Separate StreamObservers do not need to be synchronized together; incoming and outgoing directions are independent. Since individual StreamObservers are not thread-safe, if multiple threads will be writing to a StreamObserver concurrently, the application must synchronize calls.

@li-zoe-x
Copy link
Author

This is most likely caused by multiple server threads writing to the same StreamObserver without synchronization that causes mismatch with Netty reference counting.

Separate StreamObservers do not need to be synchronized together; incoming and outgoing directions are independent. Since individual StreamObservers are not thread-safe, if multiple threads will be writing to a StreamObserver concurrently, the application must synchronize calls.

ths, we are trying this

@fishjam
Copy link

fishjam commented Mar 4, 2025

I might meet same issue. when I use nativemem in async-profiler to check my app. there is similar leak report.
Image

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

No branches or pull requests

3 participants