Skip to content

Buffer LEAK detected by ResourceLeakDetector in AuthenticationPayloadExchangeConverter #9661

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

Closed
kevinat opened this issue Apr 20, 2021 · 2 comments
Assignees
Labels
in: rsocket status: backported An issue that has been backported to maintenance branches type: bug A general bug

Comments

@kevinat
Copy link

kevinat commented Apr 20, 2021

Describe the bug

Stack trace:

[ERROR] io.netty.util.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:385)
	io.netty.buffer.AbstractByteBufAllocator.directBuffer(AbstractByteBufAllocator.java:187)
	io.netty.buffer.AbstractByteBufAllocator.directBuffer(AbstractByteBufAllocator.java:173)
	io.netty.buffer.AbstractByteBufAllocator.buffer(AbstractByteBufAllocator.java:107)
	org.springframework.security.rsocket.authentication.AuthenticationPayloadExchangeConverter.authentication(AuthenticationPayloadExchangeConverter.java:74)
	org.springframework.security.rsocket.authentication.AuthenticationPayloadExchangeConverter.lambda$convert$1(AuthenticationPayloadExchangeConverter.java:66)
	reactor.core.publisher.FluxFlatMap.trySubscribeScalarMap(FluxFlatMap.java:151)
	reactor.core.publisher.MonoFlatMap.subscribeOrReturn(MonoFlatMap.java:53)
	reactor.core.publisher.InternalMonoOperator.subscribe(InternalMonoOperator.java:57)
	reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:52)
	reactor.core.publisher.Mono.subscribe(Mono.java:4046)
	reactor.core.publisher.MonoIgnoreThen$ThenIgnoreMain.drain(MonoIgnoreThen.java:173)
	reactor.core.publisher.MonoIgnoreThen.subscribe(MonoIgnoreThen.java:56)
	reactor.core.publisher.InternalMonoOperator.subscribe(InternalMonoOperator.java:64)
	reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:52)
	reactor.core.publisher.InternalMonoOperator.subscribe(InternalMonoOperator.java:64)
	io.rsocket.core.RSocketResponder.handleRequestResponse(RSocketResponder.java:345)
	io.rsocket.core.RSocketResponder.handleFrame(RSocketResponder.java:200)
	reactor.core.publisher.LambdaSubscriber.onNext(LambdaSubscriber.java:160)
	io.rsocket.core.ClientServerInputMultiplexer$InternalDuplexConnection.onNext(ClientServerInputMultiplexer.java:248)
	io.rsocket.core.ClientServerInputMultiplexer.onNext(ClientServerInputMultiplexer.java:129)
	io.rsocket.core.ClientServerInputMultiplexer.onNext(ClientServerInputMultiplexer.java:48)
	io.rsocket.core.SetupHandlingDuplexConnection.onNext(SetupHandlingDuplexConnection.java:118)
	io.rsocket.core.SetupHandlingDuplexConnection.onNext(SetupHandlingDuplexConnection.java:19)
	reactor.core.publisher.FluxMap$MapSubscriber.onNext(FluxMap.java:120)
	reactor.netty.channel.FluxReceive.drainReceiver(FluxReceive.java:267)
	reactor.netty.channel.FluxReceive.onInboundNext(FluxReceive.java:377)
	reactor.netty.channel.ChannelOperations.onInboundNext(ChannelOperations.java:381)
	reactor.netty.http.server.HttpServerOperations.onInboundNext(HttpServerOperations.java:559)
	reactor.netty.http.server.WebsocketServerOperations.onInboundNext(WebsocketServerOperations.java:161)
	reactor.netty.channel.ChannelOperationsHandler.channelRead(ChannelOperationsHandler.java:94)
	io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
	io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
	io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
	io.rsocket.transport.netty.server.BaseWebsocketServerTransport$PongHandler.channelRead(BaseWebsocketServerTransport.java:63)
	io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
	io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
	io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
	io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:324)
	io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:296)
	io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
	io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
	io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
	io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
	io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
	io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
	io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
	io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166)
	io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:719)
	io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:655)
	io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:581)
	io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493)
	io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
	io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
	io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
	java.base/java.lang.Thread.run(Thread.java:834)

To Reproduce
Enable RSocket security, run for a while, when make rsocket request again, error stack prints.

Expected behavior

Maybe this ByteBuf should be release?

74:		ByteBuf rawAuthentication = ByteBufAllocator.DEFAULT.buffer().writeBytes(authenticationMetadata);
@kevinat kevinat added status: waiting-for-triage An issue we've not yet triaged type: bug A general bug labels Apr 20, 2021
@jzheaux
Copy link
Contributor

jzheaux commented Apr 21, 2021

According to https://netty.io/wiki/reference-counted-objects.html, allocated buffers need to be proactively released, so I imagine that the code needs to be changed to look something like:

ByteBuf rawAuthentication = ByteBufAllocator.DEFAULT.buffer();
try {
  // ... produce Authentication
} finally {
    rawAuthentication.release();
}

Would you be able to submit a pull request?

@jzheaux jzheaux added in: rsocket and removed status: waiting-for-triage An issue we've not yet triaged labels Apr 21, 2021
@kevinat
Copy link
Author

kevinat commented Apr 22, 2021

Pull request submit: #9671

jzheaux pushed a commit that referenced this issue Apr 26, 2021
@spring-projects-issues spring-projects-issues added the status: backported An issue that has been backported to maintenance branches label Apr 26, 2021
jzheaux pushed a commit that referenced this issue Apr 26, 2021
akohli96 pushed a commit to akohli96/spring-security that referenced this issue Aug 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: rsocket status: backported An issue that has been backported to maintenance branches type: bug A general bug
Projects
None yet
Development

No branches or pull requests

4 participants