You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by ni...@apache.org on 2022/09/27 13:36:33 UTC

[pulsar] branch branch-2.11 updated: [improve][broker] fix broker irrational behavior when it is closing (#17085)

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

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


The following commit(s) were added to refs/heads/branch-2.11 by this push:
     new 96be15c3bff [improve][broker] fix broker irrational behavior when it is closing (#17085)
96be15c3bff is described below

commit 96be15c3bfff985090727ad3f3736ea8c758538d
Author: Qiang Huang <HQ...@users.noreply.github.com>
AuthorDate: Sun Aug 28 13:31:56 2022 +0800

    [improve][broker] fix broker irrational behavior when it is closing (#17085)
    
    (cherry picked from commit 453872359f6d824c19186f8f6d2fa954dae71e69)
---
 .../src/main/java/org/apache/pulsar/broker/PulsarService.java  |  7 +++++++
 .../main/java/org/apache/pulsar/broker/service/ServerCnx.java  | 10 ++++++++++
 2 files changed, 17 insertions(+)

diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/broker/PulsarService.java b/pulsar-broker/src/main/java/org/apache/pulsar/broker/PulsarService.java
index 23338dab023..b28318de89c 100644
--- a/pulsar-broker/src/main/java/org/apache/pulsar/broker/PulsarService.java
+++ b/pulsar-broker/src/main/java/org/apache/pulsar/broker/PulsarService.java
@@ -1244,6 +1244,13 @@ public class PulsarService implements AutoCloseable, ShutdownService {
         return this.state;
     }
 
+    /**
+     * check the current pulsar service is running, including Started and Init state.
+     */
+    public boolean isRunning() {
+        return this.state == State.Started || this.state == State.Init;
+    }
+
     /**
      * Get a reference of the current <code>LeaderElectionService</code> instance associated with the current
      * <code>PulsarService</code> instance.
diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java b/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java
index e3df87eeb02..25bd769a8bf 100644
--- a/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java
+++ b/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java
@@ -452,6 +452,16 @@ public class ServerCnx extends PulsarHandler implements TransportCnx {
             return;
         }
 
+        if (!this.service.getPulsar().isRunning()) {
+            if (log.isDebugEnabled()) {
+                log.debug("[{}] Failed lookup topic {} due to pulsar service is not ready: {} state", remoteAddress,
+                        topicName, this.service.getPulsar().getState().toString());
+            }
+            ctx.writeAndFlush(newLookupErrorResponse(ServerError.ServiceNotReady,
+                    "Failed due to pulsar service is not ready", requestId));
+            return;
+        }
+
         final Semaphore lookupSemaphore = service.getLookupRequestSemaphore();
         if (lookupSemaphore.tryAcquire()) {
             if (invalidOriginalPrincipal(originalPrincipal)) {