Skip to content

Commit 92525fb

Browse files
normanmaurerApache9
authored andcommitted
HBASE-27180 Fix multiple possible buffer leaks (#4597)
* Fix multiple possible buffer leaks Motivation: When using ByteBuf you need to be very careful about releasing it as otherwise you might leak data. There were various places in the code-base where such a leak could happen. Modifications: - Fix possible buffer leaks - Ensure we call touch(...) so its easier to debug buffer leaks Result: Fix buffer leaks * Formatting * Revert some changes as requested * revert touch * Also release checksum and header buffers Signed-off-by: Duo Zhang <zhangduo@apache.org> (cherry picked from commit 2197b38)
1 parent 11283ca commit 92525fb

3 files changed

Lines changed: 10 additions & 1 deletion

File tree

hbase-asyncfs/src/main/java/org/apache/hadoop/hbase/io/asyncfs/FanOutOneBlockAsyncDFSOutput.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,12 @@ private void flushBuffer(CompletableFuture<Long> future, ByteBuf dataBuf,
429429
future.completeExceptionally(new IOException("stream already broken"));
430430
// it's the one we have just pushed or just a no-op
431431
waitingAckQueue.removeFirst();
432+
433+
checksumBuf.release();
434+
headerBuf.release();
435+
436+
// This method takes ownership of the dataBuf so we need release it before returning.
437+
dataBuf.release();
432438
return;
433439
}
434440
// TODO: we should perhaps measure time taken per DN here;

hbase-asyncfs/src/main/java/org/apache/hadoop/hbase/io/asyncfs/FanOutOneBlockAsyncDFSOutputSaslHelper.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,8 @@ public void flush(ChannelHandlerContext ctx) throws Exception {
662662
}
663663

664664
@Override
665-
public void close(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception {
665+
public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
666+
// Release buffer on removal.
666667
cBuf.release();
667668
cBuf = null;
668669
}

hbase-asyncfs/src/test/java/org/apache/hadoop/hbase/io/asyncfs/TestFanOutOneBlockAsyncDFSOutputHang.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
185185
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
186186
if (!(msg instanceof ByteBuf)) {
187187
ctx.fireChannelRead(msg);
188+
} else {
189+
((ByteBuf) msg).release();
188190
}
189191
}
190192
});

0 commit comments

Comments
 (0)