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

[Darwin] MTRDevice resub logic should reset backoff as needed #37624

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/darwin/Framework/CHIP/MTRDevice_Concrete.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1031,8 +1031,9 @@ - (void)_triggerResubscribeWithReason:(NSString *)reason nodeLikelyReachable:(BO
// in fact be reachable yet; we won't know until we have managed to
// establish a CASE session. And at that point, our subscription will
// trigger the state change as needed.
BOOL shouldReattemptSubscription = NO;
if (self.reattemptingSubscription) {
[self _reattemptSubscriptionNowIfNeededWithReason:reason];
shouldReattemptSubscription = YES;
} else {
readClientToResubscribe = self.matterCPPObjectsHolder.readClient;
subscriptionCallback = self.matterCPPObjectsHolder.subscriptionCallback;
Expand All @@ -1048,9 +1049,15 @@ - (void)_triggerResubscribeWithReason:(NSString *)reason nodeLikelyReachable:(BO
subscriptionCallback->ResetResubscriptionBackoff();
}
readClientToResubscribe->TriggerResubscribeIfScheduled(reason.UTF8String);
} else if (_internalDeviceState == MTRInternalDeviceStateSubscribing && nodeLikelyReachable) {
} else if (((_internalDeviceState == MTRInternalDeviceStateSubscribing) || shouldReattemptSubscription) && nodeLikelyReachable) {
// If we have reason to suspect that the node is now reachable and we haven't established a
// CASE session yet, let's consider it to be stalled and invalidate the pairing session.

// Reset back off for framework resubscription
os_unfair_lock_lock(&self->_lock);
[self _setLastSubscriptionAttemptWait:0];
os_unfair_lock_unlock(&self->_lock);

mtr_weakify(self);
[self._concreteController asyncGetCommissionerOnMatterQueue:^(Controller::DeviceCommissioner * commissioner) {
mtr_strongify(self);
Expand All @@ -1061,6 +1068,11 @@ - (void)_triggerResubscribeWithReason:(NSString *)reason nodeLikelyReachable:(BO
caseSessionMgr->ReleaseSession(commissioner->GetPeerScopedId(self->_nodeID.unsignedLongLongValue));
} errorHandler:nil /* not much we can do */];
}

// Reattempt subscription after the above ReleaseSession call to avoid churn
if (shouldReattemptSubscription) {
[self _reattemptSubscriptionNowIfNeededWithReason:reason];
}
}

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