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 43b4ff6 Fix deadlock caused by ExecutorService::close (#11882) 43b4ff6 is described below commit 43b4ff6aaeef6969c73af6e3742f57554f76e1ca Author: Yunze Xu <xyzinfern...@163.com> AuthorDate: Fri Sep 3 00:53:12 2021 +0800 Fix deadlock caused by ExecutorService::close (#11882) --- pulsar-client-cpp/lib/ClientConnection.cc | 6 +++++- pulsar-client-cpp/lib/ExecutorService.cc | 8 +++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/pulsar-client-cpp/lib/ClientConnection.cc b/pulsar-client-cpp/lib/ClientConnection.cc index fc3582d..3f01063 100644 --- a/pulsar-client-cpp/lib/ClientConnection.cc +++ b/pulsar-client-cpp/lib/ClientConnection.cc @@ -569,7 +569,11 @@ void ClientConnection::handleRead(const boost::system::error_code& err, size_t b if (err || bytesTransferred == 0) { if (err) { - LOG_ERROR(cnxString_ << "Read failed: " << err.message()); + if (err == boost::asio::error::operation_aborted) { + LOG_DEBUG(cnxString_ << "Read failed: " << err.message()); + } else { + LOG_ERROR(cnxString_ << "Read operation was cancelled"); + } } // else: bytesTransferred == 0, which means server has closed the connection close(); } else if (bytesTransferred < minReadSize) { diff --git a/pulsar-client-cpp/lib/ExecutorService.cc b/pulsar-client-cpp/lib/ExecutorService.cc index e056f0f..e0e382b 100644 --- a/pulsar-client-cpp/lib/ExecutorService.cc +++ b/pulsar-client-cpp/lib/ExecutorService.cc @@ -73,11 +73,9 @@ void ExecutorService::close() { io_service_->stop(); work_.reset(); - // If this thread is attempting to join itself, do not. The destructor's - // call to close will handle joining if it does not occur here. This also ensures - // join is not called twice since it is not re-entrant on windows - if (std::this_thread::get_id() != worker_.get_id() && worker_.joinable()) { - worker_.join(); + // Detach the worker thread instead of join to avoid potential deadlock + if (worker_.joinable()) { + worker_.detach(); } }