From b37ab87e3689badbf0651cbc041b0833e96e2b24 Mon Sep 17 00:00:00 2001 From: dorjesinpo <129227380+dorjesinpo@users.noreply.github.com> Date: Thu, 19 Dec 2024 16:16:27 -0500 Subject: [PATCH] fix: protecting RemoteQueue::expirePendingMessagesDispatched Signed-off-by: dorjesinpo <129227380+dorjesinpo@users.noreply.github.com> --- src/groups/mqb/mqbblp/mqbblp_remotequeue.cpp | 15 +++++++++++---- src/groups/mqb/mqbblp/mqbblp_remotequeue.h | 3 +++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/groups/mqb/mqbblp/mqbblp_remotequeue.cpp b/src/groups/mqb/mqbblp/mqbblp_remotequeue.cpp index 06795b7be..72dd9eafe 100644 --- a/src/groups/mqb/mqbblp/mqbblp_remotequeue.cpp +++ b/src/groups/mqb/mqbblp/mqbblp_remotequeue.cpp @@ -43,6 +43,7 @@ #include #include #include +#include // BDE #include @@ -454,7 +455,8 @@ RemoteQueue::RemoteQueue(QueueState* state, int ackWindowSize, StateSpPool* statePool, bslma::Allocator* allocator) -: d_state_p(state) +: d_self(this, allocator) +, d_state_p(state) , d_queueEngine_mp(0) , d_pendingMessages(allocator) , d_pendingConfirms(allocator) @@ -553,6 +555,7 @@ void RemoteQueue::resetState() erasePendingMessages(d_pendingMessages.end()); + d_self.invalidate(); if (d_pendingMessagesTimerEventHandle) { scheduler()->cancelEventAndWait(&d_pendingMessagesTimerEventHandle); // 'expirePendingMessagesDispatched' does not restart timer if @@ -585,6 +588,7 @@ void RemoteQueue::close() BSLS_ASSERT_SAFE(d_pendingMessages.size() == 0); + d_self.invalidate(); if (d_pendingMessagesTimerEventHandle) { scheduler()->cancelEventAndWait(&d_pendingMessagesTimerEventHandle); // 'expirePendingMessagesDispatched' does not restart timer if @@ -970,8 +974,9 @@ void RemoteQueue::postMessage(const bmqp::PutHeader& putHeaderIn, scheduler()->scheduleEvent( &d_pendingMessagesTimerEventHandle, time, - bdlf::BindUtil::bind(&RemoteQueue::expirePendingMessages, - this)); + bdlf::BindUtil::bind(bmqu::WeakMemFnUtil::weakMemFn( + &RemoteQueue::expirePendingMessages, + d_self.acquireWeak()))); } } @@ -1355,7 +1360,9 @@ void RemoteQueue::expirePendingMessagesDispatched() scheduler()->scheduleEvent( &d_pendingMessagesTimerEventHandle, time, - bdlf::BindUtil::bind(&RemoteQueue::expirePendingMessages, this)); + bdlf::BindUtil::bind(bmqu::WeakMemFnUtil::weakMemFn( + &RemoteQueue::expirePendingMessages, + d_self.acquireWeak()))); BALL_LOG_DEBUG << d_state_p->uri() << ": will check again to expire" << " pending PUSH messages in " diff --git a/src/groups/mqb/mqbblp/mqbblp_remotequeue.h b/src/groups/mqb/mqbblp/mqbblp_remotequeue.h index 0a8b36cc4..4c639a8ba 100644 --- a/src/groups/mqb/mqbblp/mqbblp_remotequeue.h +++ b/src/groups/mqb/mqbblp/mqbblp_remotequeue.h @@ -45,6 +45,7 @@ #include #include +#include // BDE #include @@ -184,6 +185,8 @@ class RemoteQueue { private: // DATA + bmqu::SharedResource d_self; + QueueState* d_state_p; bslma::ManagedPtr d_queueEngine_mp;