This is an automated email from the ASF dual-hosted git repository.

chenhang pushed a commit to branch branch-4.14
in repository https://gitbox.apache.org/repos/asf/bookkeeper.git


The following commit(s) were added to refs/heads/branch-4.14 by this push:
     new 6cbe65520a [Branch 4.14] Fix potential memory leak. (#3530)
6cbe65520a is described below

commit 6cbe65520ad1725d67572b0d8a979e06d9daa3e6
Author: Yan Zhao <[email protected]>
AuthorDate: Thu Oct 27 13:11:25 2022 +0800

    [Branch 4.14] Fix potential memory leak. (#3530)
    
    * Fix byteBuf potential memory leak problem.
    
    * [Branch-4.14] Fix TLS test local port case problem (#3557)
    
    Descriptions of the changes in this PR:
    
    When we config as follow:
    ```
                conf.setDisableServerSocketBind(true);
                conf.setEnableLocalTransport(true);
    ```
    The BookieNettyServer will create jvmBootstrap, it binds the address by 
bookieId.
    
    
https://github.com/apache/bookkeeper/blob/255416a8552f34e5fd50231bbeed77e0945b63e3/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/BookieNettyServer.java#L374-L428
    At line_426, it use bookieId to bind, there is a flag about 
`BookKeeperClusterTestCase#useUUIDasBookieId`, it set uuid to bookieId.
    When the client connects to the server, the remoteAddress 
`local:a4367111-5740-40dd-a8b2-0fcb2995398b` is strange, the resolve logic  
throw java.lang.ArrayIndexOutOfBoundsException.
    
https://github.com/apache/bookkeeper/blob/255416a8552f34e5fd50231bbeed77e0945b63e3/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/PerChannelBookieClient.java#L1502-L1515
    
    The master branch looks good, The pr #2723 remove logic.
    ```
            // use a random BookieId
            if (useUUIDasBookieId) {
                conf.setBookieId(UUID.randomUUID().toString());
            }
    ```
---
 .../main/java/org/apache/bookkeeper/proto/PacketProcessorBase.java  | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git 
a/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/PacketProcessorBase.java
 
b/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/PacketProcessorBase.java
index 91f054c005..a6ac0ad6ae 100644
--- 
a/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/PacketProcessorBase.java
+++ 
b/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/PacketProcessorBase.java
@@ -110,6 +110,9 @@ abstract class PacketProcessorBase<T extends Request> 
extends SafeRunnable {
                 requestProcessor.getRequestStats().getChannelWriteStats()
                     .registerFailedEvent(MathUtils.elapsedNanos(writeNanos), 
TimeUnit.NANOSECONDS);
                 
statsLogger.registerFailedEvent(MathUtils.elapsedNanos(enqueueNanos), 
TimeUnit.NANOSECONDS);
+                if (response instanceof BookieProtocol.Response) {
+                    ((BookieProtocol.Response) response).release();
+                }
                 return;
             } else {
                 requestProcessor.invalidateBlacklist(channel);
@@ -119,6 +122,9 @@ abstract class PacketProcessorBase<T extends Request> 
extends SafeRunnable {
         if (channel.isActive()) {
             channel.writeAndFlush(response, channel.voidPromise());
         } else {
+            if (response instanceof BookieProtocol.Response) {
+                ((BookieProtocol.Response) response).release();
+            }
             LOGGER.debug("Netty channel {} is inactive, "
                     + "hence bypassing netty channel writeAndFlush during 
sendResponse", channel);
         }

Reply via email to