You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by eo...@apache.org on 2022/06/21 09:23:15 UTC

[pulsar] branch branch-2.9 updated: Transactions: fix race in TransactionMetaStoreHandler (#16147)

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

eolivelli pushed a commit to branch branch-2.9
in repository https://gitbox.apache.org/repos/asf/pulsar.git


The following commit(s) were added to refs/heads/branch-2.9 by this push:
     new 803173149df Transactions: fix race in TransactionMetaStoreHandler (#16147)
803173149df is described below

commit 803173149df1f65d083fe66cc306750f843f4a45
Author: Enrico Olivelli <eo...@apache.org>
AuthorDate: Tue Jun 21 03:23:51 2022 +0200

    Transactions: fix race in TransactionMetaStoreHandler (#16147)
    
    ### Motivation
    Fixes #15375
    
    the NPE happens because internalPinnedExecutor has not been assigned yet.
    
    ### Modifications
    
    Refactor the constructor, in a way that "this" is not accessed from another thread while the constructor is not done yet.
    
    (cherry picked from commit ec276da53231bc01eb44e9cdc106b5174915691f)
---
 .../org/apache/pulsar/client/impl/TransactionMetaStoreHandler.java | 7 +++++--
 .../client/impl/transaction/TransactionCoordinatorClientImpl.java  | 2 ++
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/TransactionMetaStoreHandler.java b/pulsar-client/src/main/java/org/apache/pulsar/client/impl/TransactionMetaStoreHandler.java
index 82fc89ca0a1..73df89dd6ae 100644
--- a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/TransactionMetaStoreHandler.java
+++ b/pulsar-client/src/main/java/org/apache/pulsar/client/impl/TransactionMetaStoreHandler.java
@@ -103,9 +103,12 @@ public class TransactionMetaStoreHandler extends HandlerState implements Connect
                 .create(),
             this);
         this.connectFuture = connectFuture;
-        this.connectionHandler.grabCnx();
+        this.internalPinnedExecutor = pulsarClient.getInternalExecutorService();
         this.timer = pulsarClient.timer();
-        internalPinnedExecutor = pulsarClient.getInternalExecutorService();
+    }
+
+    public void start() {
+        this.connectionHandler.grabCnx();
     }
 
     @Override
diff --git a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/transaction/TransactionCoordinatorClientImpl.java b/pulsar-client/src/main/java/org/apache/pulsar/client/impl/transaction/TransactionCoordinatorClientImpl.java
index e8baec784a7..c320d13e166 100644
--- a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/transaction/TransactionCoordinatorClientImpl.java
+++ b/pulsar-client/src/main/java/org/apache/pulsar/client/impl/transaction/TransactionCoordinatorClientImpl.java
@@ -94,6 +94,7 @@ public class TransactionCoordinatorClientImpl implements TransactionCoordinatorC
                                     i, pulsarClient, getTCAssignTopicName(i), connectFuture);
                             handlers[i] = handler;
                             handlerMap.put(i, handler);
+                            handler.start();
                         }
                     } else {
                         handlers = new TransactionMetaStoreHandler[1];
@@ -103,6 +104,7 @@ public class TransactionCoordinatorClientImpl implements TransactionCoordinatorC
                                 getTCAssignTopicName(-1), connectFuture);
                         handlers[0] = handler;
                         handlerMap.put(0, handler);
+                        handler.start();
                     }
 
                     STATE_UPDATER.set(TransactionCoordinatorClientImpl.this, State.READY);