Skip to content

Commit a2a25fb

Browse files
Make removeDevice drop the subscription for an MTRDevice. (#33767)
MTRDevice uses auto-resubscribe subscriptions. We had tests that set up a device, then did removeDevice, but that did not clear the subscription, and any attempts to clear it on the server side would cause it to try to re-subscribe if the subscription drop was detected. When invalidating an MTRDevice, we should tear down its subscription.
1 parent 72450e4 commit a2a25fb

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/darwin/Framework/CHIP/MTRDevice.mm

+12-3
Original file line numberDiff line numberDiff line change
@@ -788,9 +788,18 @@ - (void)invalidate
788788
// attempt, since we now have no delegate.
789789
_reattemptingSubscription = NO;
790790

791-
// We do not change _internalDeviceState here, because we might still have a
792-
// subscription. In that case, _internalDeviceState will update when the
793-
// subscription is actually terminated.
791+
[_deviceController asyncDispatchToMatterQueue:^{
792+
// Destroy the read client and callback (has to happen on the Matter
793+
// queue, to avoid deleting objects that are being referenced), to
794+
// tear down the subscription. We will get no more callbacks from
795+
// the subscrption after this point.
796+
std::lock_guard lock(self->_lock);
797+
self->_currentReadClient = nullptr;
798+
self->_currentSubscriptionCallback = nullptr;
799+
800+
[self _changeInternalState:MTRInternalDeviceStateUnsubscribed];
801+
}
802+
errorHandler:nil];
794803

795804
[self _stopConnectivityMonitoring];
796805

0 commit comments

Comments
 (0)