Skip to content

Commit

Permalink
Fix TSan failure on Darwin. (#27426)
Browse files Browse the repository at this point in the history
We could end up logging after Matter stack shutdown and when a different stack
was being configured, which would cause a thread race.

Also fixes a situation where we could try to resubscribe to things after our
MTRDevice has been invalidated.

Fixes #27425
  • Loading branch information
bzbarsky-apple authored and pull[bot] committed Oct 19, 2023
1 parent 5475424 commit 2186624
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/darwin/Framework/CHIP/MTRDevice.mm
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,10 @@ - (void)invalidate

_weakDelegate = nil;

// Make sure we don't try to resubscribe if we have a pending resubscribe
// attempt, since we now have no delegate.
_reattemptingSubscription = NO;

os_unfair_lock_unlock(&self->_lock);
}

Expand Down Expand Up @@ -336,7 +340,8 @@ - (void)_handleSubscriptionReset
// if there is no delegate then also do not retry
id<MTRDeviceDelegate> delegate = _weakDelegate.strongObject;
if (!delegate) {
MTR_LOG_DEFAULT("%@ no delegate - do not reattempt subscription", self);
// NOTE: Do not log anythig here: we have been invalidated, and the
// Matter stack might already be torn down.
os_unfair_lock_unlock(&self->_lock);
return;
}
Expand Down

0 comments on commit 2186624

Please sign in to comment.