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 2022/12/12 09:56:34 UTC

[GitHub] [pulsar] RobertIndie commented on a diff in pull request #14287: [fix][client] Close dead producer and retry producer

RobertIndie commented on code in PR #14287:
URL: https://github.com/apache/pulsar/pull/14287#discussion_r1045609383


##########
pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConsumerImpl.java:
##########
@@ -1026,8 +1028,9 @@ public CompletableFuture<Void> closeAsync() {
             closeConsumerTasks();
             deregisterFromClientCnx();
             client.cleanupConsumer(this);
-            failPendingReceive().whenComplete((r, t) -> closeFuture.complete(null));
-            return closeFuture;
+            failPendingReceive().whenComplete((r, t) -> closeConsumerFuture.complete(null));
+            closeFutures.addAll(closeDeadAndRetryProducer());

Review Comment:
   Is there a case that the consumer is disconnected but the DLQ and retry producer are not closed?



##########
pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConsumerImpl.java:
##########
@@ -1049,12 +1052,34 @@ public CompletableFuture<Void> closeAsync() {
                 if (ignoreException && exception != null) {
                     log.debug("Exception ignored in closing consumer", exception);
                 }
-                cleanupAtClose(closeFuture, ignoreException ? null : exception);
+                cleanupAtClose(closeConsumerFuture, ignoreException ? null : exception);
                 return null;
             });
         }
+        closeFutures.add(closeConsumerFuture);
+        return CompletableFuture.allOf(closeFutures.toArray(new CompletableFuture[0]));
+    }
 
-        return closeFuture;
+    private List<CompletableFuture<Void>> closeDeadAndRetryProducer() {
+        final List<CompletableFuture<Void>> closeFutures = new ArrayList<>();
+        if (this.deadLetterProducer != null) {
+            try {
+                deadLetterProducer.whenComplete((r, t) -> {
+                    if (r != null) {
+                        closeFutures.add(r.closeAsync());

Review Comment:
   You should add `whenComplete` to closeFuturres. Otherwise, the deadLetterProducer may not be closed.



##########
pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConsumerImpl.java:
##########
@@ -1049,12 +1052,34 @@ public CompletableFuture<Void> closeAsync() {
                 if (ignoreException && exception != null) {
                     log.debug("Exception ignored in closing consumer", exception);
                 }
-                cleanupAtClose(closeFuture, ignoreException ? null : exception);
+                cleanupAtClose(closeConsumerFuture, ignoreException ? null : exception);
                 return null;
             });
         }
+        closeFutures.add(closeConsumerFuture);
+        return CompletableFuture.allOf(closeFutures.toArray(new CompletableFuture[0]));

Review Comment:
   Please use `FutureUtil.waitForAll`



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

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