Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pulsar-client-cpp/lib/ClientConnection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1338,11 +1338,14 @@ void ClientConnection::close() {

if (keepAliveTimer_) {
keepAliveTimer_->cancel();
keepAliveTimer_.reset();
}

if (consumerStatsRequestTimer_) {
consumerStatsRequestTimer_->cancel();
consumerStatsRequestTimer_.reset();
}

for (ProducersMap::iterator it = producers.begin(); it != producers.end(); ++it) {
HandlerBase::handleDisconnection(ResultConnectError, shared_from_this(), it->second);
}
Expand Down
13 changes: 13 additions & 0 deletions pulsar-client-cpp/lib/ConnectionPool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,19 @@ ConnectionPool::ConnectionPool(const ClientConfiguration& conf, ExecutorServiceP
poolConnections_(poolConnections),
mutex_() {}

ConnectionPool::~ConnectionPool() {
std::unique_lock<std::mutex> lock(mutex_);
if (poolConnections_) {
for (auto cnxIt = pool_.begin(); cnxIt != pool_.end(); cnxIt++) {
ClientConnectionPtr cnx = cnxIt->second.lock();
if (cnx && !cnx->isClosed()) {
cnx->close();
}
}
pool_.clear();
}
}

Future<Result, ClientConnectionWeakPtr> ConnectionPool::getConnectionAsync(
const std::string& logicalAddress, const std::string& physicalAddress) {
std::unique_lock<std::mutex> lock(mutex_);
Expand Down
2 changes: 2 additions & 0 deletions pulsar-client-cpp/lib/ConnectionPool.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class PULSAR_PUBLIC ConnectionPool {
ConnectionPool(const ClientConfiguration& conf, ExecutorServiceProviderPtr executorProvider,
const AuthenticationPtr& authentication, bool poolConnections = true);

~ConnectionPool();

/**
* Get a connection from the pool.
* <p>
Expand Down
17 changes: 13 additions & 4 deletions pulsar-client-cpp/lib/ProducerImpl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,6 @@ ProducerImpl::ProducerImpl(ClientImplPtr client, const std::string& topic, const

ProducerImpl::~ProducerImpl() {
LOG_DEBUG(getName() << "~ProducerImpl");
if (dataKeyGenTImer_) {
dataKeyGenTImer_->cancel();
}
closeAsync(ResultCallback());
printStats();
}
Expand Down Expand Up @@ -473,6 +470,8 @@ void ProducerImpl::printStats() {
void ProducerImpl::closeAsync(CloseCallback callback) {
Lock lock(mutex_);

cancelTimers();

if (state_ != Ready) {
lock.unlock();
if (callback) {
Expand Down Expand Up @@ -682,10 +681,20 @@ void ProducerImpl::start() { HandlerBase::start(); }
void ProducerImpl::shutdown() {
Lock lock(mutex_);
state_ = Closed;
cancelTimers();
producerCreatedPromise_.setFailed(ResultAlreadyClosed);
}

void ProducerImpl::cancelTimers() {
if (dataKeyGenTImer_) {
dataKeyGenTImer_->cancel();
dataKeyGenTImer_.reset();
}

if (sendTimer_) {
sendTimer_->cancel();
sendTimer_.reset();
}
producerCreatedPromise_.setFailed(ResultAlreadyClosed);
}

bool ProducerImplCmp::operator()(const ProducerImplPtr& a, const ProducerImplPtr& b) const {
Expand Down
2 changes: 2 additions & 0 deletions pulsar-client-cpp/lib/ProducerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ class ProducerImpl : public HandlerBase,
bool encryptMessage(proto::MessageMetadata& metadata, SharedBuffer& payload,
SharedBuffer& encryptedPayload);

void cancelTimers();

typedef std::unique_lock<std::mutex> Lock;

ProducerConfiguration conf_;
Expand Down