Skip to content

Commit

Permalink
Delete persisted subscriptions that are in subscription resumption st…
Browse files Browse the repository at this point in the history
…ate 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.
  • Loading branch information
dvdm-qorvo committed Feb 24, 2025
1 parent 43a8a9b commit 7c120c8
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion src/app/InteractionModelEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -723,14 +723,45 @@ Protocols::InteractionModel::Status InteractionModelEngine::OnReadInitialRequest
if (handler->IsFromSubscriber(*apExchangeContext))
{
ChipLogProgress(InteractionModel,
"Deleting previous subscription from NodeId: " ChipLogFormatX64 ", FabricIndex: %u",
"Deleting previous active subscription from NodeId: " ChipLogFormatX64 ", FabricIndex: %u",
ChipLogValueX64(apExchangeContext->GetSessionHandle()->AsSecureSession()->GetPeerNodeId()),
apExchangeContext->GetSessionHandle()->GetFabricIndex());
handler->Close();
}

return Loop::Continue;
});

#if CHIP_CONFIG_PERSIST_SUBSCRIPTIONS
// Also remove persisted subscriptions by checking if matching nodeId and fabricIndex
// iterate over persisted subscriptions and remove the ones that match the nodeId and fabricIndex
SubscriptionResumptionStorage::SubscriptionInfo subscriptionInfo;
auto * iterator = mpSubscriptionResumptionStorage->IterateSubscriptions();

while (iterator->Next(subscriptionInfo))
{
if (subscriptionInfo.mNodeId == apExchangeContext->GetSessionHandle()->AsSecureSession()->GetPeerNodeId() &&
subscriptionInfo.mFabricIndex == apExchangeContext->GetSessionHandle()->GetFabricIndex())
{
ChipLogProgress(InteractionModel,
"Deleting previous non-active subscription from NodeId: " ChipLogFormatX64 ", FabricIndex: %u",
ChipLogValueX64(subscriptionInfo.mNodeId), subscriptionInfo.mFabricIndex);
mpSubscriptionResumptionStorage->Delete(subscriptionInfo.mNodeId, subscriptionInfo.mFabricIndex,
subscriptionInfo.mSubscriptionId);
}
}
iterator->Release();
#endif // CHIP_CONFIG_PERSIST_SUBSCRIPTIONS
#ifdef CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION
// If we have no subscriptions to resume, we can cancel the Timer, to make sure it is cleared in the case,
// we deleted a subscription in resumption mode.
if (!HasSubscriptionsToResume())
{
mpExchangeMgr->GetSessionManager()->SystemLayer()->CancelTimer(ResumeSubscriptionsTimerCallback, this);
mSubscriptionResumptionScheduled = false;
mNumSubscriptionResumptionRetries = 0;
}
#endif // CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION
}

{
Expand Down

0 comments on commit 7c120c8

Please sign in to comment.