eolivelli commented on a change in pull request #14538:
URL: https://github.com/apache/pulsar/pull/14538#discussion_r817619359



##########
File path: 
pulsar-client/src/main/java/org/apache/pulsar/client/impl/PulsarClientImpl.java
##########
@@ -710,14 +713,30 @@ public void close() throws PulsarClientException {
         final CompletableFuture<Void> closeFuture = new CompletableFuture<>();
         List<CompletableFuture<Void>> futures = new ArrayList<>();
 
-        producers.forEach(p -> futures.add(p.closeAsync()));
-        consumers.forEach(c -> futures.add(c.closeAsync()));
+        producers.forEach(p -> futures.add(p.closeAsync().handle((__, t) -> {
+            log.error("Error closing producer {}", p, t);

Review comment:
       this is an error only if "t" is not null

##########
File path: 
pulsar-client/src/main/java/org/apache/pulsar/client/impl/PulsarClientImpl.java
##########
@@ -710,14 +713,30 @@ public void close() throws PulsarClientException {
         final CompletableFuture<Void> closeFuture = new CompletableFuture<>();
         List<CompletableFuture<Void>> futures = new ArrayList<>();
 
-        producers.forEach(p -> futures.add(p.closeAsync()));
-        consumers.forEach(c -> futures.add(c.closeAsync()));
+        producers.forEach(p -> futures.add(p.closeAsync().handle((__, t) -> {
+            log.error("Error closing producer {}", p, t);
+            return null;
+        })));
+        consumers.forEach(c -> futures.add(c.closeAsync().handle((__, t) -> {
+            log.error("Error closing consumer {}", c, t);

Review comment:
       this is an error only if "t" is not null

##########
File path: 
pulsar-client/src/main/java/org/apache/pulsar/client/impl/PulsarClientImpl.java
##########
@@ -710,14 +713,30 @@ public void close() throws PulsarClientException {
         final CompletableFuture<Void> closeFuture = new CompletableFuture<>();
         List<CompletableFuture<Void>> futures = new ArrayList<>();
 
-        producers.forEach(p -> futures.add(p.closeAsync()));
-        consumers.forEach(c -> futures.add(c.closeAsync()));
+        producers.forEach(p -> futures.add(p.closeAsync().handle((__, t) -> {
+            log.error("Error closing producer {}", p, t);
+            return null;
+        })));
+        consumers.forEach(c -> futures.add(c.closeAsync().handle((__, t) -> {
+            log.error("Error closing consumer {}", c, t);
+            return null;
+        })));
 
         // Need to run the shutdown sequence in a separate thread to prevent 
deadlocks
         // If there are consumers or producers that need to be shutdown we 
cannot use the same thread
         // to shutdown the EventLoopGroup as well as that would be trying to 
shutdown itself thus a deadlock
         // would happen
-        FutureUtil.waitForAll(futures).thenRun(() -> new Thread(() -> {
+        CompletableFuture<Void> combinedFuture = 
FutureUtil.waitForAll(futures);
+        ScheduledExecutorService shutdownExecutor = 
Executors.newSingleThreadScheduledExecutor(
+                new 
DefaultThreadFactory("pulsar-client-shutdown-timeout-scheduler"));
+        FutureUtil.addTimeoutHandling(combinedFuture, 
Duration.ofSeconds(CLOSE_TIMEOUT_SECONDS),
+                shutdownExecutor, () -> 
FutureUtil.createTimeoutException("Closing producers and consumers timed out.",
+                        PulsarClientImpl.class, "closeAsync"));
+        combinedFuture.whenComplete((__, t) -> new Thread(() -> {

Review comment:
       shall we give a name to this Thread and also set it as "deamon" ?
   
   

##########
File path: 
pulsar-client/src/main/java/org/apache/pulsar/client/impl/PulsarClientImpl.java
##########
@@ -710,14 +713,30 @@ public void close() throws PulsarClientException {
         final CompletableFuture<Void> closeFuture = new CompletableFuture<>();
         List<CompletableFuture<Void>> futures = new ArrayList<>();
 
-        producers.forEach(p -> futures.add(p.closeAsync()));
-        consumers.forEach(c -> futures.add(c.closeAsync()));
+        producers.forEach(p -> futures.add(p.closeAsync().handle((__, t) -> {
+            log.error("Error closing producer {}", p, t);
+            return null;
+        })));
+        consumers.forEach(c -> futures.add(c.closeAsync().handle((__, t) -> {
+            log.error("Error closing consumer {}", c, t);
+            return null;
+        })));
 
         // Need to run the shutdown sequence in a separate thread to prevent 
deadlocks
         // If there are consumers or producers that need to be shutdown we 
cannot use the same thread
         // to shutdown the EventLoopGroup as well as that would be trying to 
shutdown itself thus a deadlock
         // would happen
-        FutureUtil.waitForAll(futures).thenRun(() -> new Thread(() -> {
+        CompletableFuture<Void> combinedFuture = 
FutureUtil.waitForAll(futures);
+        ScheduledExecutorService shutdownExecutor = 
Executors.newSingleThreadScheduledExecutor(

Review comment:
       is it is too heavy weight to create 2 threads (one here and one below) 
every time we "close" a PulsarClient ?




-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to