Skip to content

Commit 7c120c8

Browse files
committed
Delete persisted subscriptions that are in subscription resumption state when a subscribeRequest command comes in with keepSubscription flag set to false from the same subscriber
The Matter specification is saying: "If KeepSubscriptions is FALSE, all existing or pending subscriptions on the publisher for this subscriber SHALL be terminated." Currently only active readHandlers and corresponding persisted subscription were removed. The subscriptions that were persisted and in subscription resumption mode, were kept in persistent storage, keeping the subscription resumption mechanism active, so pending subscriptions were not terminated. This fixes, when a subscribeRequest come in with keepSubscriptions flag set to false, these persisted non-active subscriptions can be deleted as well and the subscription resumption mechanism can be stopped if no other subscription were resuming.
1 parent 43a8a9b commit 7c120c8

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

src/app/InteractionModelEngine.cpp

+32-1
Original file line numberDiff line numberDiff line change
@@ -723,14 +723,45 @@ Protocols::InteractionModel::Status InteractionModelEngine::OnReadInitialRequest
723723
if (handler->IsFromSubscriber(*apExchangeContext))
724724
{
725725
ChipLogProgress(InteractionModel,
726-
"Deleting previous subscription from NodeId: " ChipLogFormatX64 ", FabricIndex: %u",
726+
"Deleting previous active subscription from NodeId: " ChipLogFormatX64 ", FabricIndex: %u",
727727
ChipLogValueX64(apExchangeContext->GetSessionHandle()->AsSecureSession()->GetPeerNodeId()),
728728
apExchangeContext->GetSessionHandle()->GetFabricIndex());
729729
handler->Close();
730730
}
731731

732732
return Loop::Continue;
733733
});
734+
735+
#if CHIP_CONFIG_PERSIST_SUBSCRIPTIONS
736+
// Also remove persisted subscriptions by checking if matching nodeId and fabricIndex
737+
// iterate over persisted subscriptions and remove the ones that match the nodeId and fabricIndex
738+
SubscriptionResumptionStorage::SubscriptionInfo subscriptionInfo;
739+
auto * iterator = mpSubscriptionResumptionStorage->IterateSubscriptions();
740+
741+
while (iterator->Next(subscriptionInfo))
742+
{
743+
if (subscriptionInfo.mNodeId == apExchangeContext->GetSessionHandle()->AsSecureSession()->GetPeerNodeId() &&
744+
subscriptionInfo.mFabricIndex == apExchangeContext->GetSessionHandle()->GetFabricIndex())
745+
{
746+
ChipLogProgress(InteractionModel,
747+
"Deleting previous non-active subscription from NodeId: " ChipLogFormatX64 ", FabricIndex: %u",
748+
ChipLogValueX64(subscriptionInfo.mNodeId), subscriptionInfo.mFabricIndex);
749+
mpSubscriptionResumptionStorage->Delete(subscriptionInfo.mNodeId, subscriptionInfo.mFabricIndex,
750+
subscriptionInfo.mSubscriptionId);
751+
}
752+
}
753+
iterator->Release();
754+
#endif // CHIP_CONFIG_PERSIST_SUBSCRIPTIONS
755+
#ifdef CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION
756+
// If we have no subscriptions to resume, we can cancel the Timer, to make sure it is cleared in the case,
757+
// we deleted a subscription in resumption mode.
758+
if (!HasSubscriptionsToResume())
759+
{
760+
mpExchangeMgr->GetSessionManager()->SystemLayer()->CancelTimer(ResumeSubscriptionsTimerCallback, this);
761+
mSubscriptionResumptionScheduled = false;
762+
mNumSubscriptionResumptionRetries = 0;
763+
}
764+
#endif // CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION
734765
}
735766

736767
{

0 commit comments

Comments
 (0)