mrniko / netty-socketio

Socket.IO server implemented on Java. Realtime java framework
Apache License 2.0
6.7k stars 1.64k forks source link

if ack returns after the timeout trigger ,a IllegalStateException will be thrown #964

Open BianJianyu opened 4 months ago

BianJianyu commented 4 months ago

version:2.0.9

  1. onTimeout() will remove ackCallback,however ackCallback is necessary while package decoding. file:com/corundumstudio/socketio/ack/AckManager.java line:157 image

    file:com/corundumstudio/socketio/protocol/PacketDecoder.java line:300

    image
  2. if callback is null, the byteBuf will not be read. And the the loop will run second time! file:com/corundumstudio/socketio/handler/InPacketHandler.java line:64 image
  3. however the data in the buffer is already wrong, so it cannot get the right type, and then throw the IllegalStateException file:com/corundumstudio/socketio/protocol/PacketType.java line:42 image
malinGH commented 4 months ago

if (callback != null) { ByteBufInputStream in = new ByteBufInputStream(frame); AckArgs args = jsonSupport.readAckArgs(in, callback); packet.setData(args.getArgs()); }else { frame.clear(); } what if I write it like this? @mrniko

965

malinGH commented 3 months ago

3A6E8155-C3B6-41e6-BD11-3EAC9929600D E853EA39-0E46-411E-83D0-1540D3F19ADE this is test result ,nothing exception

mrniko commented 3 months ago

@malinGH

What about the case then there are other packets next to this packet? they won't be parsed if bytebuf readIndex reset to zero

mrniko commented 3 months ago

It's better to use the code below.

frame.skipBytes(frame.readableBytes());

Now the buffer was consumed completely.

malinGH commented 3 months ago

let me try

malinGH commented 3 months ago

@mrniko Test is fail, You need to test this version, branch:master 截屏2024-03-27 15 53 23

malinGH commented 3 months ago

截屏2024-03-27 15 57 26

malinGH commented 3 months ago

6437A52C-EE5F-437a-B958-1BCE6E44AAAC