Skip to content

Commit

Permalink
[fix][offload] Fix memory leak while Offloading ledgers (apache#18500)
Browse files Browse the repository at this point in the history
(cherry picked from commit 6ff7d45)
  • Loading branch information
eolivelli committed Nov 16, 2022
1 parent b82dca1 commit fcdf50e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ public void close() throws IOException {
// And through debug, writeBlobStore.uploadMultipartPart in the offload method also will trigger
// the close method.
// So we add the close variable to avoid release paddingBuf twice.
if (!close.compareAndSet(false, true)) {
if (close.compareAndSet(false, true)) {
super.close();
dataBlockHeaderStream.close();
if (!entriesByteBuf.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import io.netty.buffer.Unpooled;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.lang.reflect.Field;
import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.Iterator;
Expand Down Expand Up @@ -798,4 +799,18 @@ public void testReadTillLacWithSmallBuffer() throws Exception {

inputStream.close();
}

@Test
public void testCloseReleaseResources() throws Exception {
ReadHandle readHandle = new MockReadHandle(1, 10, 10);

BlockAwareSegmentInputStreamImpl inputStream = new BlockAwareSegmentInputStreamImpl(readHandle, 0, 1024);
inputStream.read();
Field field = BlockAwareSegmentInputStreamImpl.class.getDeclaredField("paddingBuf");
field.setAccessible(true);
ByteBuf paddingBuf = (ByteBuf) field.get(inputStream);
assertEquals(1, paddingBuf.refCnt());
inputStream.close();
assertEquals(0, paddingBuf.refCnt());
}
}

0 comments on commit fcdf50e

Please sign in to comment.