Revert "[#2761] ChannelOutboundBuffer can cause data-corruption because of caching ByteBuffers"
This reverts commit 4059c9f354
.
This commit is contained in:
parent
1e6fddfc72
commit
2c03030950
@ -352,17 +352,31 @@ public final class ChannelOutboundBuffer {
|
|||||||
|
|
||||||
if (readableBytes > 0) {
|
if (readableBytes > 0) {
|
||||||
nioBufferSize += readableBytes;
|
nioBufferSize += readableBytes;
|
||||||
int count = buf.nioBufferCount();
|
int count = entry.count;
|
||||||
|
if (count == -1) {
|
||||||
|
//noinspection ConstantValueVariableUse
|
||||||
|
entry.count = count = buf.nioBufferCount();
|
||||||
|
}
|
||||||
int neededSpace = nioBufferCount + count;
|
int neededSpace = nioBufferCount + count;
|
||||||
if (neededSpace > nioBuffers.length) {
|
if (neededSpace > nioBuffers.length) {
|
||||||
nioBuffers = expandNioBufferArray(nioBuffers, neededSpace, nioBufferCount);
|
nioBuffers = expandNioBufferArray(nioBuffers, neededSpace, nioBufferCount);
|
||||||
NIO_BUFFERS.set(threadLocalMap, nioBuffers);
|
NIO_BUFFERS.set(threadLocalMap, nioBuffers);
|
||||||
}
|
}
|
||||||
if (count == 1) {
|
if (count == 1) {
|
||||||
ByteBuffer nioBuf = buf.internalNioBuffer(readerIndex, readableBytes);
|
ByteBuffer nioBuf = entry.buf;
|
||||||
|
if (nioBuf == null) {
|
||||||
|
// cache ByteBuffer as it may need to create a new ByteBuffer instance if its a
|
||||||
|
// derived buffer
|
||||||
|
entry.buf = nioBuf = buf.internalNioBuffer(readerIndex, readableBytes);
|
||||||
|
}
|
||||||
nioBuffers[nioBufferCount ++] = nioBuf;
|
nioBuffers[nioBufferCount ++] = nioBuf;
|
||||||
} else {
|
} else {
|
||||||
ByteBuffer[] nioBufs = buf.nioBuffers(readerIndex, readableBytes);
|
ByteBuffer[] nioBufs = entry.bufs;
|
||||||
|
if (nioBufs == null) {
|
||||||
|
// cached ByteBuffers as they may be expensive to create in terms
|
||||||
|
// of Object allocation
|
||||||
|
entry.bufs = nioBufs = buf.nioBuffers();
|
||||||
|
}
|
||||||
nioBufferCount = fillBufferArray(nioBufs, nioBuffers, nioBufferCount);
|
nioBufferCount = fillBufferArray(nioBufs, nioBuffers, nioBufferCount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -572,10 +586,13 @@ public final class ChannelOutboundBuffer {
|
|||||||
private final Handle handle;
|
private final Handle handle;
|
||||||
Entry next;
|
Entry next;
|
||||||
Object msg;
|
Object msg;
|
||||||
|
ByteBuffer[] bufs;
|
||||||
|
ByteBuffer buf;
|
||||||
ChannelPromise promise;
|
ChannelPromise promise;
|
||||||
long progress;
|
long progress;
|
||||||
long total;
|
long total;
|
||||||
int pendingSize;
|
int pendingSize;
|
||||||
|
int count = -1;
|
||||||
boolean cancelled;
|
boolean cancelled;
|
||||||
|
|
||||||
private Entry(Handle handle) {
|
private Entry(Handle handle) {
|
||||||
@ -603,6 +620,8 @@ public final class ChannelOutboundBuffer {
|
|||||||
pendingSize = 0;
|
pendingSize = 0;
|
||||||
total = 0;
|
total = 0;
|
||||||
progress = 0;
|
progress = 0;
|
||||||
|
bufs = null;
|
||||||
|
buf = null;
|
||||||
return pSize;
|
return pSize;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@ -610,11 +629,14 @@ public final class ChannelOutboundBuffer {
|
|||||||
|
|
||||||
void recycle() {
|
void recycle() {
|
||||||
next = null;
|
next = null;
|
||||||
|
bufs = null;
|
||||||
|
buf = null;
|
||||||
msg = null;
|
msg = null;
|
||||||
promise = null;
|
promise = null;
|
||||||
progress = 0;
|
progress = 0;
|
||||||
total = 0;
|
total = 0;
|
||||||
pendingSize = 0;
|
pendingSize = 0;
|
||||||
|
count = -1;
|
||||||
cancelled = false;
|
cancelled = false;
|
||||||
RECYCLER.recycle(this, handle);
|
RECYCLER.recycle(this, handle);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user