Skip to content

Commit

Permalink
[fix][c++ client] avoid race condition causing double callback on clo…
Browse files Browse the repository at this point in the history
…se (#15508)

* avoid race condition causing double callback on close

* Update pulsar-client-cpp/lib/ClientImpl.cc

Co-authored-by: Yunze Xu <xyzinfernity@163.com>
  • Loading branch information
2 people authored and merlimat committed May 9, 2022
1 parent 6d16025 commit 2762bbc
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions pulsar-client-cpp/lib/ClientImpl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2762bbc

Please sign in to comment.