[Matter.framework] MTRAsyncWorkItem::initWithQueue will assert when the delayed scheduleSubscriptionPool fires after the deallocation of the MTRDevice (#35987)
diff --git a/src/darwin/Framework/CHIP/MTRDevice_Concrete.mm b/src/darwin/Framework/CHIP/MTRDevice_Concrete.mm
index 869f8b6..539754d 100644
--- a/src/darwin/Framework/CHIP/MTRDevice_Concrete.mm
+++ b/src/darwin/Framework/CHIP/MTRDevice_Concrete.mm
@@ -1170,6 +1170,12 @@
mtr_weakify(self);
dispatch_block_t workBlockToQueue = ^{
mtr_strongify(self);
+ if (nil == self) {
+ // This block may be delayed by a specified number of nanoseconds, potentially running after the device is deallocated.
+ // If so, MTRAsyncWorkItem::initWithQueue will assert on a nil queue, which will cause a crash.
+ return;
+ }
+
// In the case where a resubscription triggering event happened and already established, running the work block should result in a no-op
MTRAsyncWorkItem * workItem = [[MTRAsyncWorkItem alloc] initWithQueue:self.queue];
[workItem setReadyHandler:^(id _Nonnull context, NSInteger retryCount, MTRAsyncWorkCompletionBlock _Nonnull completion) {