Skip to content

Instantly share code, notes, and snippets.

@TheGreyGhost
Last active August 29, 2015 14:22
Show Gist options
  • Save TheGreyGhost/62d3d37fcef29700eb9a to your computer and use it in GitHub Desktop.
Save TheGreyGhost/62d3d37fcef29700eb9a to your computer and use it in GitHub Desktop.
Race condition in SimpleNetworkWrapper; error locations
Breakpoint on IndexOutOfBoundsException
AbstractByteBuf::
@Override
public ByteBuf readerIndex(int readerIndex) {
if (readerIndex < 0 || readerIndex > writerIndex) {
throw new IndexOutOfBoundsException(String.format(
"readerIndex: %d (expected: 0 <= readerIndex <= writerIndex(%d))", readerIndex, writerIndex));
}
this.readerIndex = readerIndex;
return this;
}
Further up the call stack is
AbstractByteBuf::
@Override
public ByteBuf writeBytes(ByteBuf src, int length) {
if (length > src.readableBytes()) {
throw new IndexOutOfBoundsException(String.format(
"length(%d) exceeds src.readableBytes(%d) where src is: %s", length, src.readableBytes(), src));
}
// at this point we have just checked that there is at least 7 bytes remaining to be read.
writeBytes(src, src.readerIndex(), length);
src.readerIndex(src.readerIndex() + length); ///<--- here; length = 7, but causes a failure, i.e. something has advanced src by 1.
return this;
}
S3FPacketCustomPayload::
public void writePacketData(PacketBuffer buf) throws IOException
{
buf.writeString(this.channel);
synchronized(this) { //This may be access multiple times, from multiple threads, lets be safe.
this.data.markReaderIndex(); // markedReaderIndex == 0
buf.writeBytes((ByteBuf)this.data); // <------------- here
this.data.resetReaderIndex();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment