Skip to content

Commit

Permalink
Merge pull request #530 from lenguyenthanh/fix-oobe
Browse files Browse the repository at this point in the history
Fix IndexOutOfBoundsException when frame.content() is empty
  • Loading branch information
ornicar authored Feb 23, 2024
2 parents 981950b + e9e620e commit 16b4c03
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 16b4c03

Please sign in to comment.