You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2021/04/28 12:31:17 UTC

[GitHub] [pulsar] congbobo184 commented on a change in pull request #10407: [Transaction] Fix transaction buffer client channel not active problem.

congbobo184 commented on a change in pull request #10407:
URL: https://github.com/apache/pulsar/pull/10407#discussion_r622128765



##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/transaction/buffer/impl/TransactionBufferHandlerImpl.java
##########
@@ -116,24 +124,26 @@ public TransactionBufferHandlerImpl(PulsarClient pulsarClient,
 
     private CompletableFuture<TxnID> endTxn(long requestId, String topic, ByteBuf cmd, CompletableFuture<TxnID> cb) {
         OpRequestSend op = OpRequestSend.create(requestId, topic, cmd, cb);
-        pendingRequests.put(requestId, op);
-        cmd.retain();
         try {
             cache.get(topic).whenComplete((clientCnx, throwable) -> {
                 if (throwable == null) {
-                    try {
+                    if (clientCnx.ctx().channel().isActive()) {
                         clientCnx.registerTransactionBufferHandler(TransactionBufferHandlerImpl.this);
+                        synchronized (TransactionBufferHandlerImpl.class) {
+                            pendingRequests.put(requestId, op);
+                            cmd.retain();
+                        }
                         clientCnx.ctx().writeAndFlush(cmd, clientCnx.ctx().voidPromise());
-                    } catch (Exception e) {
+                    } else {
                         cache.invalidate(topic);
-                        cb.completeExceptionally(e);
-                        pendingRequests.remove(requestId);
+                        cb.completeExceptionally(
+                                new PulsarClientException.LookupException(topic + " endTxn channel is not active"));
                         op.recycle();
                     }
                 } else {
+                    log.error("endTxn error topic: [{}]", topic, throwable);
                     cache.invalidate(topic);
                     cb.completeExceptionally(throwable);
-                    pendingRequests.remove(requestId);

Review comment:
       if run here, the request don't put in `pendingRequests`. so remove this line




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org