From e8c4c20c51fbe2ea8f9af9268a3a405a947ffd18 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Thu, 22 Jun 2023 22:58:41 -0400 Subject: [PATCH] Fix TSan failure on Darwin. 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 https://github.com/project-chip/connectedhomeip/issues/27425 --- src/darwin/Framework/CHIP/MTRDevice.mm | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/darwin/Framework/CHIP/MTRDevice.mm b/src/darwin/Framework/CHIP/MTRDevice.mm index dc158c89f768ec..0ae15d02002d9e 100644 --- a/src/darwin/Framework/CHIP/MTRDevice.mm +++ b/src/darwin/Framework/CHIP/MTRDevice.mm @@ -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); } @@ -336,7 +340,8 @@ - (void)_handleSubscriptionReset // if there is no delegate then also do not retry id 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; }