You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by te...@apache.org on 2023/04/23 05:49:10 UTC

[pulsar] branch branch-2.10 updated: [fix][meta] deadlock of zkSessionWatcher when zkConnection loss (#20122)

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

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


The following commit(s) were added to refs/heads/branch-2.10 by this push:
     new 6c99903b08d [fix][meta] deadlock of zkSessionWatcher when zkConnection loss (#20122)
6c99903b08d is described below

commit 6c99903b08d46c0e7c3d32e42b27f98b86e2819a
Author: tiny-rain <hu...@126.com>
AuthorDate: Sun Apr 23 13:45:03 2023 +0800

    [fix][meta] deadlock of zkSessionWatcher when zkConnection loss (#20122)
---
 .../java/org/apache/pulsar/metadata/impl/ZKSessionWatcher.java    | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/pulsar-metadata/src/main/java/org/apache/pulsar/metadata/impl/ZKSessionWatcher.java b/pulsar-metadata/src/main/java/org/apache/pulsar/metadata/impl/ZKSessionWatcher.java
index a350d4a5b3d..d49c3913262 100644
--- a/pulsar-metadata/src/main/java/org/apache/pulsar/metadata/impl/ZKSessionWatcher.java
+++ b/pulsar-metadata/src/main/java/org/apache/pulsar/metadata/impl/ZKSessionWatcher.java
@@ -80,7 +80,11 @@ public class ZKSessionWatcher implements AutoCloseable, Watcher {
     }
 
     // task that runs every TICK_TIME to check zk connection
-    private synchronized void checkConnectionStatus() {
+    // NOT ThreadSafe:
+    // If zk client can't ensure the order, it may lead to problems.
+    // Currently,we only use it in single thread, it will be fine. but we shouldn't leave any potential problems
+    // in the future.
+    private void checkConnectionStatus() {
         try {
             CompletableFuture<Watcher.Event.KeeperState> future = new CompletableFuture<>();
             zk.exists("/", false, (StatCallback) (rc, path, ctx, stat) -> {
@@ -125,7 +129,7 @@ public class ZKSessionWatcher implements AutoCloseable, Watcher {
         currentStatus = SessionEvent.SessionLost;
     }
 
-    private void checkState(Watcher.Event.KeeperState zkClientState) {
+    private synchronized void checkState(Watcher.Event.KeeperState zkClientState) {
         switch (zkClientState) {
         case Expired:
             if (currentStatus != SessionEvent.SessionLost) {