From 3f1c284595e5fe0c2cf84fc22d9c5959dc727898 Mon Sep 17 00:00:00 2001 From: Yong Zhang Date: Thu, 9 Jun 2022 16:52:28 +0800 Subject: [PATCH] Fix the V2 AddRequest object leak issue --- **Motivation** If the request is a V2 add request, we retained the data's reference when creating the AddRequest object. To avoid the object leak, we need to release the reference if we met any errors before sending it. --- .../apache/bookkeeper/proto/PerChannelBookieClient.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/PerChannelBookieClient.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/PerChannelBookieClient.java index f798e8001a9..05923787315 100644 --- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/PerChannelBookieClient.java +++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/PerChannelBookieClient.java @@ -1135,6 +1135,14 @@ private void writeAndFlush(final Channel channel, StringUtils.requestToString(request)); errorOut(key, BKException.Code.TooManyRequestsException); + + // If the request is a V2 add request, we retained the data's reference when creating the AddRequest + // object. To avoid the object leak, we need to release the reference if we met any errors + // before sending it. + if (request instanceof BookieProtocol.AddRequest) { + BookieProtocol.AddRequest ar = (BookieProtocol.AddRequest) request; + ar.recycle(); + } return; }