This is an automated email from the ASF dual-hosted git repository.
mmerli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar.git
The following commit(s) were added to refs/heads/master by this push:
new 421fa1fb264 [fix][c++ client] avoid race condition causing double
callback on close (#15508)
421fa1fb264 is described below
commit 421fa1fb26483d4bf8832834341862789d1f3b5b
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 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