You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by si...@apache.org on 2019/06/30 11:58:40 UTC

[pulsar] branch master updated: [pulsar-broker] fix deadlock on get-status rest-api call (#4616)

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

sijie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar.git


The following commit(s) were added to refs/heads/master by this push:
     new f272df9  [pulsar-broker] fix deadlock on get-status rest-api call (#4616)
f272df9 is described below

commit f272df9211b2d8acf77284ed3e00f6a68b173358
Author: Rajan Dhabalia <rd...@apache.org>
AuthorDate: Sun Jun 30 04:58:35 2019 -0700

    [pulsar-broker] fix deadlock on get-status rest-api call (#4616)
    
    ### Motivation
    
    due to some issue if broker fails to complete topic-loading then getting stats of that topic blocks web-thread.
    
    ```
    "pulsar-web-30-13" #242 prio=5 os_prio=0 tid=0x00002b0b3c001000 nid=0x2540 waiting on condition [0x00002b0aa7d0a000]
       java.lang.Thread.State: WAITING (parking)
            at sun.misc.Unsafe.park(Native Method)
            - parking to wait for  <0x000000072560a180> (a java.util.concurrent.CompletableFuture$Signaller)
            at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
            at java.util.concurrent.CompletableFuture$Signaller.block(CompletableFuture.java:1693)
            at java.util.concurrent.ForkJoinPool.managedBlock(ForkJoinPool.java:3323)
            at java.util.concurrent.CompletableFuture.waitingGet(CompletableFuture.java:1729)
            at java.util.concurrent.CompletableFuture.join(CompletableFuture.java:1934)
            at org.apache.pulsar.broker.admin.impl.PersistentTopicsBase.getTopicReference(PersistentTopicsBase.java:1253)
            at org.apache.pulsar.broker.admin.impl.PersistentTopicsBase.internalGetStats(PersistentTopicsBase.java:592)
            at org.apache.pulsar.broker.admin.v1.PersistentTopics.getStats(PersistentTopics.java:240)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
            at java.lang.reflect.Method.invoke(Method.java:498)
    ```
---
 .../pulsar/broker/admin/impl/PersistentTopicsBase.java       | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/PersistentTopicsBase.java b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/PersistentTopicsBase.java
index 29dc789..5ed35cf 100644
--- a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/PersistentTopicsBase.java
+++ b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/PersistentTopicsBase.java
@@ -39,7 +39,6 @@ import java.util.Set;
 import java.util.TreeMap;
 import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.ExecutionException;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.atomic.AtomicReference;
@@ -1339,8 +1338,15 @@ public class PersistentTopicsBase extends AdminResource {
      * Get the Topic object reference from the Pulsar broker
      */
     private Topic getTopicReference(TopicName topicName) {
-        return pulsar().getBrokerService().getTopicIfExists(topicName.toString()).join()
-                .orElseThrow(() -> topicNotFoundReason(topicName));
+        try {
+            return pulsar().getBrokerService().getTopicIfExists(topicName.toString())
+                    .get(pulsar().getConfiguration().getZooKeeperSessionTimeoutMillis(), TimeUnit.MILLISECONDS)
+                    .orElseThrow(() -> topicNotFoundReason(topicName));
+        } catch (RestException e) {
+            throw e;
+        } catch (Exception e) {
+            throw new RestException(e);
+        }
     }
 
     private RestException topicNotFoundReason(TopicName topicName) {