This is an automated email from the ASF dual-hosted git repository.
mmerli pushed a commit to branch branch-2.8
in repository https://gitbox.apache.org/repos/asf/pulsar.git
The following commit(s) were added to refs/heads/branch-2.8 by this push:
new b2cafb375c0 [fix][c++ client] avoid race condition causing double
callback on close (#15508)
b2cafb375c0 is described below
commit b2cafb375c0cc665a834aa55ccfaf0d786e5c092
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 eea761d44db..32c4a4d067f 100644
--- a/pulsar-client-cpp/lib/ClientImpl.cc
+++ b/pulsar-client-cpp/lib/ClientImpl.cc
@@ -525,8 +525,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