@@ -1031,8 +1031,9 @@ - (void)_triggerResubscribeWithReason:(NSString *)reason nodeLikelyReachable:(BO
1031
1031
// in fact be reachable yet; we won't know until we have managed to
1032
1032
// establish a CASE session. And at that point, our subscription will
1033
1033
// trigger the state change as needed.
1034
+ BOOL shouldReattemptSubscription = NO;
1034
1035
if (self.reattemptingSubscription) {
1035
- [self _reattemptSubscriptionNowIfNeededWithReason:reason] ;
1036
+ shouldReattemptSubscription = YES ;
1036
1037
} else {
1037
1038
readClientToResubscribe = self.matterCPPObjectsHolder.readClient;
1038
1039
subscriptionCallback = self.matterCPPObjectsHolder.subscriptionCallback;
@@ -1048,9 +1049,15 @@ - (void)_triggerResubscribeWithReason:(NSString *)reason nodeLikelyReachable:(BO
1048
1049
subscriptionCallback->ResetResubscriptionBackoff();
1049
1050
}
1050
1051
readClientToResubscribe->TriggerResubscribeIfScheduled(reason.UTF8String);
1051
- } else if (_internalDeviceState == MTRInternalDeviceStateSubscribing && nodeLikelyReachable) {
1052
+ } else if ((( _internalDeviceState == MTRInternalDeviceStateSubscribing) || shouldReattemptSubscription) && nodeLikelyReachable) {
1052
1053
// If we have reason to suspect that the node is now reachable and we haven't established a
1053
1054
// CASE session yet, let's consider it to be stalled and invalidate the pairing session.
1055
+
1056
+ // Reset back off for framework resubscription
1057
+ os_unfair_lock_lock(&self->_lock);
1058
+ [self _setLastSubscriptionAttemptWait:0];
1059
+ os_unfair_lock_unlock(&self->_lock);
1060
+
1054
1061
mtr_weakify(self);
1055
1062
[self._concreteController asyncGetCommissionerOnMatterQueue:^(Controller::DeviceCommissioner * commissioner) {
1056
1063
mtr_strongify(self);
@@ -1061,6 +1068,11 @@ - (void)_triggerResubscribeWithReason:(NSString *)reason nodeLikelyReachable:(BO
1061
1068
caseSessionMgr->ReleaseSession(commissioner->GetPeerScopedId(self->_nodeID.unsignedLongLongValue));
1062
1069
} errorHandler:nil /* not much we can do */];
1063
1070
}
1071
+
1072
+ // Reattempt subscription after the above ReleaseSession call to avoid churn
1073
+ if (shouldReattemptSubscription) {
1074
+ [self _reattemptSubscriptionNowIfNeededWithReason:reason];
1075
+ }
1064
1076
}
1065
1077
1066
1078
// Return YES if we are in a state where, apart from communication issues with
0 commit comments