Skip to content

Commit d6f1c32

Browse files
committed
Release the chunkBuffer if an exception is thrown whilst reading
If an exception was thrown due to an issue whilst reading the MetricFamily into the slice, the buffer wasn't released and Netty complained about ByteBuf being gc'ed without being explicitly released.
1 parent 62141f4 commit d6f1c32

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

common/src/main/java/com/zegelin/prometheus/exposition/JsonFormatChunkedInput.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,12 @@ public ByteBuf readChunk(final ChannelHandlerContext ctx) throws Exception {
466466

467467
// add slices till we hit the chunk size (or slightly over it), or hit EOF
468468
while (chunkBuffer.readableBytes() < 1024 * 1024 && state != State.EOF) {
469-
nextSlice(chunkBuffer);
469+
try {
470+
nextSlice(chunkBuffer);
471+
} catch (Exception e) {
472+
chunkBuffer.release();
473+
throw e;
474+
}
470475
}
471476

472477
return chunkBuffer;

common/src/main/java/com/zegelin/prometheus/exposition/TextFormatChunkedInput.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,8 +359,8 @@ public ByteBuf readChunk(final ChannelHandlerContext ctx) throws Exception {
359359
while (chunkBuffer.readableBytes() < 1024 * 1024 && state != State.EOF) {
360360
try {
361361
nextSlice(chunkBuffer);
362-
363362
} catch (Exception e) {
363+
chunkBuffer.release();
364364
throw e;
365365
}
366366
}

0 commit comments

Comments
 (0)