Skip to content

Commit

Permalink
修复大并发抛异常的根本原因
Browse files Browse the repository at this point in the history
  • Loading branch information
a2888409 committed Apr 21, 2016
1 parent 550a1d7 commit ccddbf0
Showing 1 changed file with 1 addition and 6 deletions.
7 changes: 1 addition & 6 deletions protobuf/src/main/java/protobuf/code/PacketDecoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected void decode(ChannelHandlerContext ctx, ByteBuf in,
return;
}

if (length > in.readableBytes()) {
if (length > in.readableBytes() - 4) {
//注意!编解码器加这种in.readInt()日志,在大并发的情况下很可能会抛数组越界异常!
//logger.error("message received is incomplete,ptoNum:{}, length:{}, readable:{}", in.readInt(), length, in.readableBytes());
in.resetReaderIndex();
Expand All @@ -46,11 +46,6 @@ protected void decode(ChannelHandlerContext ctx, ByteBuf in,

int ptoNum = in.readInt();

//此处大并发的时候可能会抛出异常再检查一次
if (length > in.readableBytes()) {
in.resetReaderIndex();
return;
}

ByteBuf byteBuf = Unpooled.buffer(length);

Expand Down

0 comments on commit ccddbf0

Please sign in to comment.