Fix a bug in internalNioBuffer() implementations of derived buffers
- A user can create multiple duplicates of a buffer and access their internal NIO buffers. (e.g. write multiple duplicates to multiple channels assigned to different event loop.) Because the derived buffers' internalNioBuffer() simply delegates the call to the original buffer, all derived buffers and the original buffer's internalNioBuffer() will return the same buffer, which will lead to a race condition. - Fixes #1739
This commit is contained in:
parent
a383988cdb
commit
20894bc99e
@ -289,7 +289,7 @@ public class DuplicatedByteBuf extends AbstractDerivedByteBuf {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ByteBuffer internalNioBuffer(int index, int length) {
|
public ByteBuffer internalNioBuffer(int index, int length) {
|
||||||
return buffer.internalNioBuffer(index, length);
|
return buffer.internalNioBuffer(index, length).duplicate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -292,7 +292,7 @@ public class ReadOnlyByteBuf extends AbstractDerivedByteBuf {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ByteBuffer internalNioBuffer(int index, int length) {
|
public ByteBuffer internalNioBuffer(int index, int length) {
|
||||||
return buffer.internalNioBuffer(index, length);
|
return buffer.internalNioBuffer(index, length).duplicate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -271,7 +271,7 @@ public class SlicedByteBuf extends AbstractDerivedByteBuf {
|
|||||||
@Override
|
@Override
|
||||||
public ByteBuffer internalNioBuffer(int index, int length) {
|
public ByteBuffer internalNioBuffer(int index, int length) {
|
||||||
checkIndex(index, length);
|
checkIndex(index, length);
|
||||||
return buffer.internalNioBuffer(index + adjustment, length);
|
return buffer.internalNioBuffer(index + adjustment, length).duplicate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -741,8 +741,7 @@ public final class SwappedByteBuf extends ByteBuf {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ByteBuffer internalNioBuffer(int index, int length) {
|
public ByteBuffer internalNioBuffer(int index, int length) {
|
||||||
// Do not mess with the internal buffer's byte order.
|
return buf.internalNioBuffer(index, length).duplicate().order(order);
|
||||||
return buf.nioBuffer(index, length).order(order);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user