Skip to content

Commit 53ee24e

Browse files
dvdm-qorvorestyled-commitsbzbarsky-apple
authored
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 (#37741)
* 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. * Restyled by whitespace * Restyled by clang-format * Added mSubscriptionId value as part of the log line * Restyled by whitespace * Restyled by clang-format * Update comment in src/app/InteractionModelEngine.cpp Co-authored-by: Boris Zbarsky <bzbarsky@apple.com> --------- Co-authored-by: Restyled.io <commits@restyled.io> Co-authored-by: Boris Zbarsky <bzbarsky@apple.com>
1 parent 2b8d74e commit 53ee24e

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

src/app/InteractionModelEngine.cpp

+34-1
Original file line numberDiff line numberDiff line change
@@ -723,14 +723,47 @@ 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 && CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION
736+
if (mpSubscriptionResumptionStorage != nullptr)
737+
{
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
748+
", FabricIndex: %u, SubscriptionId: 0x%" PRIx32,
749+
ChipLogValueX64(subscriptionInfo.mNodeId), subscriptionInfo.mFabricIndex,
750+
subscriptionInfo.mSubscriptionId);
751+
mpSubscriptionResumptionStorage->Delete(subscriptionInfo.mNodeId, subscriptionInfo.mFabricIndex,
752+
subscriptionInfo.mSubscriptionId);
753+
}
754+
}
755+
iterator->Release();
756+
757+
// If we have no subscriptions to resume, we can cancel the timer, which might be armed
758+
// if one of the subscriptions we deleted was about to be resumed.
759+
if (!HasSubscriptionsToResume())
760+
{
761+
mpExchangeMgr->GetSessionManager()->SystemLayer()->CancelTimer(ResumeSubscriptionsTimerCallback, this);
762+
mSubscriptionResumptionScheduled = false;
763+
mNumSubscriptionResumptionRetries = 0;
764+
}
765+
}
766+
#endif // CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION && CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION
734767
}
735768

736769
{

0 commit comments

Comments
 (0)