Skip to content

Commit

Permalink
Make removeDevice drop the subscription for an MTRDevice. (#33767)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bzbarsky-apple authored Jun 6, 2024
1 parent 72450e4 commit a2a25fb
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/darwin/Framework/CHIP/MTRDevice.mm
Original file line number Diff line number Diff line change
Expand Up @@ -788,9 +788,18 @@ - (void)invalidate
// attempt, since we now have no delegate.
_reattemptingSubscription = NO;

// We do not change _internalDeviceState here, because we might still have a
// subscription. In that case, _internalDeviceState will update when the
// subscription is actually terminated.
[_deviceController asyncDispatchToMatterQueue:^{
// Destroy the read client and callback (has to happen on the Matter
// queue, to avoid deleting objects that are being referenced), to
// tear down the subscription. We will get no more callbacks from
// the subscrption after this point.
std::lock_guard lock(self->_lock);
self->_currentReadClient = nullptr;
self->_currentSubscriptionCallback = nullptr;

[self _changeInternalState:MTRInternalDeviceStateUnsubscribed];
}
errorHandler:nil];

[self _stopConnectivityMonitoring];

Expand Down

0 comments on commit a2a25fb

Please sign in to comment.