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: Fix ByteBuf leak in remoting transport. #1636

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,14 @@ private[pekko] class ProtobufEncoder extends MessageToMessageEncoder[Message] {
private[pekko] class ProtobufDecoder(prototype: Message) extends MessageToMessageDecoder[ByteBuf] {

override def decode(ctx: ChannelHandlerContext, msg: ByteBuf, out: java.util.List[AnyRef]): Unit = {
val bytes = ByteBufUtil.getBytes(msg)
out.add(prototype.getParserForType.parseFrom(bytes))
try {
val bytes = ByteBufUtil.getBytes(msg)
out.add(prototype.getParserForType.parseFrom(bytes))
} catch {
case NonFatal(e) => ctx.pipeline().fireExceptionCaught(e)
} finally {
msg.release()
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import io.netty.buffer.{ ByteBuf, ByteBufUtil, Unpooled }
import io.netty.channel.{ Channel, ChannelHandlerContext }
import io.netty.util.AttributeKey

import scala.util.control.NonFatal

private[remote] object TcpHandlers {
private val LISTENER = AttributeKey.valueOf[HandleEventListener]("listener")
}
Expand All @@ -56,8 +58,16 @@ private[remote] trait TcpHandlers extends CommonHandlers {
}

override def onMessage(ctx: ChannelHandlerContext, msg: ByteBuf): Unit = {
val bytes: Array[Byte] = ByteBufUtil.getBytes(msg)
if (bytes.length > 0) notifyListener(ctx.channel(), InboundPayload(ByteString(bytes)))
try {
val bytes: Array[Byte] = ByteBufUtil.getBytes(msg)
if (bytes.length > 0) notifyListener(ctx.channel(), InboundPayload(ByteString(bytes)))
} catch {
case NonFatal(e) =>
log.warning("Error while handling message from [{}]: {}", ctx.channel().remoteAddress(), e)
onException(ctx, e)
} finally {
msg.release()
}
}

override def onException(ctx: ChannelHandlerContext, e: Throwable): Unit = {
Expand Down
Loading