Skip to content

Commit 70317f9

Browse files
jtung-appleratgr
authored andcommitted
[Darwin] MTRDevice resub logic should reset backoff as needed (project-chip#37624)
* [Darwin] MTRDevice resub logic should reset backoff as needed * Improved code comment, per PR review
1 parent 6e68b1a commit 70317f9

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/darwin/Framework/CHIP/MTRDevice_Concrete.mm

+15-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,12 @@ - (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+
// The subscription reattempt here eventually asyncs onto the matter queue for session,
1073+
// and should be called after the above ReleaseSession call, to avoid churn.
1074+
if (shouldReattemptSubscription) {
1075+
[self _reattemptSubscriptionNowIfNeededWithReason:reason];
1076+
}
10641077
}
10651078

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

0 commit comments

Comments
 (0)