Skip to content
This repository was archived by the owner on Jan 24, 2024. It is now read-only.

Commit 4d2566a

Browse files
committed
[bugfix][transactions] Release memory in TransactionMarkerChannelHandler (#1867)
### Motivation Release memory in TransactionMarkerChannelHandler Co-authored-by: Enrico Olivelli <enrico.olivelli@datastax.com> (cherry picked from commit 60990bc)
1 parent e29a4c3 commit 4d2566a

1 file changed

Lines changed: 18 additions & 12 deletions

File tree

kafka-impl/src/main/java/io/streamnative/pulsar/handlers/kop/coordinator/transaction/TransactionMarkerChannelHandler.java

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import io.netty.buffer.Unpooled;
2121
import io.netty.channel.ChannelHandlerContext;
2222
import io.netty.channel.ChannelInboundHandlerAdapter;
23+
import io.netty.util.ReferenceCountUtil;
2324
import io.streamnative.pulsar.handlers.kop.security.PlainSaslServer;
2425
import java.net.InetSocketAddress;
2526
import java.nio.ByteBuffer;
@@ -121,18 +122,23 @@ public void channelInactive(ChannelHandlerContext channelHandlerContext) throws
121122

122123
@Override
123124
public void channelRead(ChannelHandlerContext channelHandlerContext, Object o) throws Exception {
124-
ByteBuffer nio = ((ByteBuf) o).nioBuffer();
125-
ResponseHeader responseHeader = ResponseHeader.parse(nio);
126-
PendingRequest pendingRequest = pendingRequestMap.remove(responseHeader.correlationId());
127-
if (pendingRequest != null) {
128-
pendingRequest.complete(responseContext.set(
129-
channelHandlerContext.channel().remoteAddress(),
130-
pendingRequest.getApiVersion(),
131-
responseHeader.correlationId(),
132-
pendingRequest.parseResponse(nio)
133-
));
134-
} else {
135-
log.error("Miss the inFlightRequest with correlationId {}.", responseHeader.correlationId());
125+
ByteBuf buffer = (ByteBuf) o;
126+
try {
127+
ByteBuffer nio = buffer.nioBuffer();
128+
ResponseHeader responseHeader = ResponseHeader.parse(nio);
129+
PendingRequest pendingRequest = pendingRequestMap.remove(responseHeader.correlationId());
130+
if (pendingRequest != null) {
131+
pendingRequest.complete(responseContext.set(
132+
channelHandlerContext.channel().remoteAddress(),
133+
pendingRequest.getApiVersion(),
134+
responseHeader.correlationId(),
135+
pendingRequest.parseResponse(nio)
136+
));
137+
} else {
138+
log.error("Miss the inFlightRequest with correlationId {}.", responseHeader.correlationId());
139+
}
140+
} finally {
141+
ReferenceCountUtil.safeRelease(buffer);
136142
}
137143
}
138144

0 commit comments

Comments
 (0)