You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by mm...@apache.org on 2022/05/09 17:14:32 UTC

[pulsar] branch branch-2.10 updated: [fix][c++ client] avoid race condition causing double callback on close (#15508)

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

mmerli 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 fa05a850e73 [fix][c++ client] avoid race condition causing double callback on close (#15508)
fa05a850e73 is described below

commit fa05a850e7356b42591fc04506496026c96ad878
Author: Matt-Esch <ma...@mattesch.info>
AuthorDate: Mon May 9 17:30:42 2022 +0100

    [fix][c++ client] avoid race condition causing double callback on close (#15508)
    
    * avoid race condition causing double callback on close
    
    * Update pulsar-client-cpp/lib/ClientImpl.cc
    
    Co-authored-by: Yunze Xu <xy...@163.com>
---
 pulsar-client-cpp/lib/ClientImpl.cc | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/pulsar-client-cpp/lib/ClientImpl.cc b/pulsar-client-cpp/lib/ClientImpl.cc
index 60e3e248c12..931fadeaae7 100644
--- a/pulsar-client-cpp/lib/ClientImpl.cc
+++ b/pulsar-client-cpp/lib/ClientImpl.cc
@@ -536,8 +536,13 @@ void ClientImpl::handleClose(Result result, SharedInt numberOfOpenHandlers, Resu
     }
     if (*numberOfOpenHandlers == 0) {
         Lock lock(mutex_);
-        state_ = Closed;
-        lock.unlock();
+        if (state_ == Closed) {
+            LOG_DEBUG("Client is already shutting down, possible race condition in handleClose");
+            return;
+        } else {
+            state_ = Closed;
+            lock.unlock();
+        }
 
         LOG_DEBUG("Shutting down producers and consumers for client");
         // handleClose() is called in ExecutorService's event loop, while shutdown() tried to wait the event