Skip to content

Commit 9186e08

Browse files
committedFeb 17, 2025
[Darwin] MTRDevice resub logic should reset backoff as needed
1 parent 7c1d6f7 commit 9186e08

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed
 

‎src/darwin/Framework/CHIP/MTRDevice_Concrete.mm

+14-2
Original file line numberDiff line numberDiff line change
@@ -1031,8 +1031,9 @@ - (void)_triggerResubscribeWithReason:(NSString *)reason nodeLikelyReachable:(BO
10311031
// in fact be reachable yet; we won't know until we have managed to
10321032
// establish a CASE session. And at that point, our subscription will
10331033
// trigger the state change as needed.
1034+
BOOL shouldReattemptSubscription = NO;
10341035
if (self.reattemptingSubscription) {
1035-
[self _reattemptSubscriptionNowIfNeededWithReason:reason];
1036+
shouldReattemptSubscription = YES;
10361037
} else {
10371038
readClientToResubscribe = self.matterCPPObjectsHolder.readClient;
10381039
subscriptionCallback = self.matterCPPObjectsHolder.subscriptionCallback;
@@ -1048,9 +1049,15 @@ - (void)_triggerResubscribeWithReason:(NSString *)reason nodeLikelyReachable:(BO
10481049
subscriptionCallback->ResetResubscriptionBackoff();
10491050
}
10501051
readClientToResubscribe->TriggerResubscribeIfScheduled(reason.UTF8String);
1051-
} else if (_internalDeviceState == MTRInternalDeviceStateSubscribing && nodeLikelyReachable) {
1052+
} else if (((_internalDeviceState == MTRInternalDeviceStateSubscribing) || shouldReattemptSubscription) && nodeLikelyReachable) {
10521053
// If we have reason to suspect that the node is now reachable and we haven't established a
10531054
// 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+
10541061
mtr_weakify(self);
10551062
[self._concreteController asyncGetCommissionerOnMatterQueue:^(Controller::DeviceCommissioner * commissioner) {
10561063
mtr_strongify(self);
@@ -1061,6 +1068,11 @@ - (void)_triggerResubscribeWithReason:(NSString *)reason nodeLikelyReachable:(BO
10611068
caseSessionMgr->ReleaseSession(commissioner->GetPeerScopedId(self->_nodeID.unsignedLongLongValue));
10621069
} errorHandler:nil /* not much we can do */];
10631070
}
1071+
1072+
// Reattempt subscription after the above ReleaseSession call to avoid churn
1073+
if (shouldReattemptSubscription) {
1074+
[self _reattemptSubscriptionNowIfNeededWithReason:reason];
1075+
}
10641076
}
10651077

10661078
// Return YES if we are in a state where, apart from communication issues with

0 commit comments

Comments
 (0)