Skip to content

Commit fee6066

Browse files
Reset retry counter for subscription resumption once subscription resumption succeeded. (#37740)
* Reset retry counter for subscription resumption once subscription resumption succeeded. A retry counter is used to monitor the number of retries done for subscription resumption. Based on this retry counter, a backoff mechanism is in place to calculate the next try for subscription resumption. How bigger the retry counter is, how longer it will take before subscription resumption is retried. It was seen that this retry counter was not reset after the subscription successfully resumed. When after that subscription resumption mechanism is kicked in again, it was using the last retry counter, leading to very big retry timings from the start. This is not desired behavior. This commit makes sure the reset counter is reset after a successful subscription resumption is seen. * Restyled by whitespace * Restyled by clang-format --------- Co-authored-by: Restyled.io <commits@restyled.io>
1 parent 7eab378 commit fee6066

3 files changed

+23
-1
lines changed

src/app/InteractionModelEngine.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -2155,5 +2155,15 @@ void InteractionModelEngine::DecrementNumSubscriptionsToResume()
21552155
}
21562156
#endif // CHIP_CONFIG_PERSIST_SUBSCRIPTIONS
21572157

2158+
#if CHIP_CONFIG_PERSIST_SUBSCRIPTIONS && CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION
2159+
void InteractionModelEngine::ResetNumSubscriptionsRetries()
2160+
{
2161+
// Check if there are any subscriptions to resume, if not the retry counter can be reset.
2162+
if (!HasSubscriptionsToResume())
2163+
{
2164+
mNumSubscriptionResumptionRetries = 0;
2165+
}
2166+
}
2167+
#endif // CHIP_CONFIG_PERSIST_SUBSCRIPTIONS && CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION
21582168
} // namespace app
21592169
} // namespace chip

src/app/InteractionModelEngine.h

+8
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,14 @@ class InteractionModelEngine : public Messaging::UnsolicitedMessageHandler,
324324
* was successful or not.
325325
*/
326326
void DecrementNumSubscriptionsToResume();
327+
#if CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION
328+
/**
329+
* @brief Function resets the number of retries of subscriptions resumption - mNumSubscriptionResumptionRetries.
330+
* This should be called after we have completed a re-subscribe attempt successfully on a persisted subscription,
331+
* or when the subscription resumption gets terminated.
332+
*/
333+
void ResetNumSubscriptionsRetries();
334+
#endif // CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION
327335
#endif // CHIP_CONFIG_PERSIST_SUBSCRIPTIONS
328336

329337
#if CONFIG_BUILD_FOR_HOST_UNIT_TEST

src/app/SubscriptionResumptionSessionEstablisher.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ void SubscriptionResumptionSessionEstablisher::HandleDeviceConnected(void * cont
113113
readHandler->OnSubscriptionResumed(sessionHandle, *establisher);
114114
#if CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION
115115
// Reset the resumption retries to 0 if subscription is resumed
116-
subscriptionInfo.mResumptionRetries = 0;
116+
subscriptionInfo.mResumptionRetries = 0;
117+
imEngine->ResetNumSubscriptionsRetries();
117118
auto * subscriptionResumptionStorage = InteractionModelEngine::GetInstance()->GetSubscriptionResumptionStorage();
118119
if (subscriptionResumptionStorage)
119120
{
@@ -157,6 +158,9 @@ void SubscriptionResumptionSessionEstablisher::HandleDeviceConnectionFailure(voi
157158
// Clean up the persistent subscription information storage.
158159
subscriptionResumptionStorage->Delete(subscriptionInfo.mNodeId, subscriptionInfo.mFabricIndex,
159160
subscriptionInfo.mSubscriptionId);
161+
#if CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION
162+
imEngine->ResetNumSubscriptionsRetries();
163+
#endif // CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION
160164
}
161165
}
162166

0 commit comments

Comments
 (0)