Last active
August 29, 2015 14:22
-
-
Save TheGreyGhost/62d3d37fcef29700eb9a to your computer and use it in GitHub Desktop.
Race condition in SimpleNetworkWrapper; error locations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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