Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

35 changes: 34 additions & 1 deletion src/app/InteractionModelEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -723,14 +723,47 @@ 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 && CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION
if (mpSubscriptionResumptionStorage != nullptr)
{
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, SubscriptionId: 0x%" PRIx32,
ChipLogValueX64(subscriptionInfo.mNodeId), subscriptionInfo.mFabricIndex,
subscriptionInfo.mSubscriptionId);
mpSubscriptionResumptionStorage->Delete(subscriptionInfo.mNodeId, subscriptionInfo.mFabricIndex,
subscriptionInfo.mSubscriptionId);
}
}
iterator->Release();

// If we have no subscriptions to resume, we can cancel the timer, which might be armed
// if one of the subscriptions we deleted was about to be resumed.
if (!HasSubscriptionsToResume())
{
mpExchangeMgr->GetSessionManager()->SystemLayer()->CancelTimer(ResumeSubscriptionsTimerCallback, this);
mSubscriptionResumptionScheduled = false;
mNumSubscriptionResumptionRetries = 0;
}
}
#endif // CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION && CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION
}

{
Expand Down
Loading