Skip to content

Commit 3cc74a4

Browse files
Make removeDevice drop the subscription for an MTRDevice.
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 24bbdf4 commit 3cc74a4

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
@@ -780,9 +780,18 @@ - (void)invalidate
780780
// attempt, since we now have no delegate.
781781
_reattemptingSubscription = NO;
782782

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

787796
[self _stopConnectivityMonitoring];
788797

0 commit comments

Comments
 (0)