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

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

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

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


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

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

    [fix][meta] deadlock of zkSessionWatcher when zkConnection loss (#20122)
    
    (cherry picked from commit d3d36bdbd22a1b1fa6cee41a91acd9ec8a4c9341)
---
 .../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 1ce01f57d4f..a8407210230 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
@@ -81,7 +81,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) -> {
@@ -126,7 +130,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) {