Skip to content

Commit

Permalink
Avoid IndexOutOfBoundsException when frame.content() is empty
Browse files Browse the repository at this point in the history
ByteBuf.getLong(0) will throw exception if it doesn't have enough
data (aka 8 bytes)
  • Loading branch information
lenguyenthanh committed Feb 22, 2024
1 parent 981950b commit a606d0b
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/main/scala/netty/FrameHandler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ final private class FrameHandler(using Executor) extends SimpleChannelInboundHan
case out => withClientOf(ctx.channel)(_ tell out)

case frame: PongWebSocketFrame =>
val lagMillis = (System.currentTimeMillis() - frame.content().getLong(0)).toInt
val pong = ClientOut.RoundPongFrame(lagMillis)
Option(ctx.channel.attr(key.client).get) foreach { _.value foreach { _ foreach (_ ! pong) } }
if frame.content().readableBytes() >= 8 then
val lagMillis = (System.currentTimeMillis() - frame.content().getLong(0)).toInt
val pong = ClientOut.RoundPongFrame(lagMillis)
Option(ctx.channel.attr(key.client).get) foreach { _.value foreach { _ foreach (_ ! pong) } }

case frame =>
logger.info("unsupported frame type: " + frame.getClass.getName)
Expand Down

0 comments on commit a606d0b

Please sign in to comment.