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
6 changes: 6 additions & 0 deletions lib/AckGroupingTrackerEnabled.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ AckGroupingTrackerEnabled::AckGroupingTrackerEnabled(ClientImplPtr clientPtr,
const HandlerBasePtr& handlerPtr, uint64_t consumerId,
long ackGroupingTimeMs, long ackGroupingMaxSize)
: AckGroupingTracker(),
isClosed_(false),
handlerWeakPtr_(handlerPtr),
consumerId_(consumerId),
nextCumulativeAckMsgId_(MessageId::earliest()),
Expand Down Expand Up @@ -110,6 +111,7 @@ void AckGroupingTrackerEnabled::addAcknowledgeCumulative(const MessageId& msgId)
}

void AckGroupingTrackerEnabled::close() {
isClosed_ = true;
this->flush();
std::lock_guard<std::mutex> lock(this->mutexTimer_);
if (this->timer_) {
Expand Down Expand Up @@ -164,6 +166,10 @@ void AckGroupingTrackerEnabled::flushAndClean() {
}

void AckGroupingTrackerEnabled::scheduleTimer() {
if (isClosed_) {
return;
}

std::lock_guard<std::mutex> lock(this->mutexTimer_);
this->timer_ = this->executor_->createDeadlineTimer();
this->timer_->expires_from_now(boost::posix_time::milliseconds(std::max(1L, this->ackGroupingTimeMs_)));
Expand Down
4 changes: 4 additions & 0 deletions lib/AckGroupingTrackerEnabled.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include <pulsar/MessageId.h>

#include <atomic>
#include <boost/asio/deadline_timer.hpp>
#include <cstdint>
#include <mutex>
Expand Down Expand Up @@ -71,6 +72,9 @@ class AckGroupingTrackerEnabled : public AckGroupingTracker {
//! Method for scheduling grouping timer.
void scheduleTimer();

//! State
std::atomic_bool isClosed_;

//! The connection handler.
HandlerBaseWeakPtr handlerWeakPtr_;

Expand Down
3 changes: 3 additions & 0 deletions lib/ConsumerImpl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1212,6 +1212,9 @@ void ConsumerImpl::closeAsync(ResultCallback originalCallback) {
const std::string& ConsumerImpl::getName() const { return consumerStr_; }

void ConsumerImpl::shutdown() {
if (ackGroupingTrackerPtr_) {
ackGroupingTrackerPtr_->close();
}
incomingMessages_.clear();
possibleSendToDeadLetterTopicMessages_.clear();
resetCnx();
Expand Down