CodecOutputList should be recycled in a finally block (#10186)
Motivation: To ensure we always recycle the CodecOutputList we should better do it in a finally block Modifications: Call CodecOutputList.recycle() in finally Result: Less chances of non-recycled lists. Related to https://github.com/netty/netty/issues/10183
This commit is contained in:
parent
1b3e1985b4
commit
4c9d7492fb
@ -279,21 +279,24 @@ public abstract class ByteToMessageDecoder extends ChannelInboundHandlerAdapter
|
||||
} catch (Exception e) {
|
||||
throw new DecoderException(e);
|
||||
} finally {
|
||||
if (cumulation != null && !cumulation.isReadable()) {
|
||||
numReads = 0;
|
||||
cumulation.release();
|
||||
cumulation = null;
|
||||
} else if (++ numReads >= discardAfterReads) {
|
||||
// We did enough reads already try to discard some bytes so we not risk to see a OOME.
|
||||
// See https://github.com/netty/netty/issues/4275
|
||||
numReads = 0;
|
||||
discardSomeReadBytes();
|
||||
}
|
||||
try {
|
||||
if (cumulation != null && !cumulation.isReadable()) {
|
||||
numReads = 0;
|
||||
cumulation.release();
|
||||
cumulation = null;
|
||||
} else if (++numReads >= discardAfterReads) {
|
||||
// We did enough reads already try to discard some bytes so we not risk to see a OOME.
|
||||
// See https://github.com/netty/netty/issues/4275
|
||||
numReads = 0;
|
||||
discardSomeReadBytes();
|
||||
}
|
||||
|
||||
int size = out.size();
|
||||
firedChannelRead |= out.insertSinceRecycled();
|
||||
fireChannelRead(ctx, out, size);
|
||||
out.recycle();
|
||||
int size = out.size();
|
||||
firedChannelRead |= out.insertSinceRecycled();
|
||||
fireChannelRead(ctx, out, size);
|
||||
} finally {
|
||||
out.recycle();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ctx.fireChannelRead(msg);
|
||||
|
@ -97,11 +97,14 @@ public abstract class MessageToMessageDecoder<I> extends ChannelInboundHandlerAd
|
||||
} catch (Exception e) {
|
||||
throw new DecoderException(e);
|
||||
} finally {
|
||||
int size = out.size();
|
||||
for (int i = 0; i < size; i ++) {
|
||||
ctx.fireChannelRead(out.getUnsafe(i));
|
||||
try {
|
||||
int size = out.size();
|
||||
for (int i = 0; i < size; i++) {
|
||||
ctx.fireChannelRead(out.getUnsafe(i));
|
||||
}
|
||||
} finally {
|
||||
out.recycle();
|
||||
}
|
||||
out.recycle();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -92,9 +92,6 @@ public abstract class MessageToMessageEncoder<I> extends ChannelOutboundHandlerA
|
||||
}
|
||||
|
||||
if (out.isEmpty()) {
|
||||
out.recycle();
|
||||
out = null;
|
||||
|
||||
throw new EncoderException(
|
||||
StringUtil.simpleClassName(this) + " must produce at least one message.");
|
||||
}
|
||||
@ -107,19 +104,22 @@ public abstract class MessageToMessageEncoder<I> extends ChannelOutboundHandlerA
|
||||
throw new EncoderException(t);
|
||||
} finally {
|
||||
if (out != null) {
|
||||
final int sizeMinusOne = out.size() - 1;
|
||||
if (sizeMinusOne == 0) {
|
||||
ctx.write(out.getUnsafe(0), promise);
|
||||
} else if (sizeMinusOne > 0) {
|
||||
// Check if we can use a voidPromise for our extra writes to reduce GC-Pressure
|
||||
// See https://github.com/netty/netty/issues/2525
|
||||
if (promise == ctx.voidPromise()) {
|
||||
writeVoidPromise(ctx, out);
|
||||
} else {
|
||||
writePromiseCombiner(ctx, out, promise);
|
||||
try {
|
||||
final int sizeMinusOne = out.size() - 1;
|
||||
if (sizeMinusOne == 0) {
|
||||
ctx.write(out.getUnsafe(0), promise);
|
||||
} else if (sizeMinusOne > 0) {
|
||||
// Check if we can use a voidPromise for our extra writes to reduce GC-Pressure
|
||||
// See https://github.com/netty/netty/issues/2525
|
||||
if (promise == ctx.voidPromise()) {
|
||||
writeVoidPromise(ctx, out);
|
||||
} else {
|
||||
writePromiseCombiner(ctx, out, promise);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
out.recycle();
|
||||
}
|
||||
out.recycle();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user