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

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


The following commit(s) were added to refs/heads/branch-2.9 by this push:
     new 2762bbc71f5 [fix][c++ client] avoid race condition causing double 
callback on close (#15508)
2762bbc71f5 is described below

commit 2762bbc71f5648a488b7dc29cb464183534d4e73
Author: Matt-Esch <[email protected]>
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 <[email protected]>
---
 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 6d9c4ed044e..dd00e3b9d45 100644
--- a/pulsar-client-cpp/lib/ClientImpl.cc
+++ b/pulsar-client-cpp/lib/ClientImpl.cc
@@ -532,8 +532,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

Reply via email to