diff --git a/src/darwin/Framework/CHIP/MTRBaseSubscriptionCallback.mm b/src/darwin/Framework/CHIP/MTRBaseSubscriptionCallback.mm index 4b313d75c9e6b6..e498a1682d52aa 100644 --- a/src/darwin/Framework/CHIP/MTRBaseSubscriptionCallback.mm +++ b/src/darwin/Framework/CHIP/MTRBaseSubscriptionCallback.mm @@ -35,6 +35,12 @@ // Reports attribute and event data if any exists void MTRBaseSubscriptionCallback::ReportData() { + // At data reporting time, nil out scheduled or currently running interimReportBlock + if (mInterimReportBlock) { + dispatch_block_cancel(mInterimReportBlock); // no-op when running from mInterimReportBlock + mInterimReportBlock = nil; + } + __block NSArray * attributeReports = mAttributeReports; mAttributeReports = nil; auto attributeCallback = mAttributeReportCallback; @@ -59,7 +65,6 @@ } mInterimReportBlock = dispatch_block_create(DISPATCH_BLOCK_INHERIT_QOS_CLASS, ^{ - mInterimReportBlock = nil; ReportData(); // Allocate reports arrays to continue accumulation mAttributeReports = [NSMutableArray new]; @@ -71,10 +76,6 @@ void MTRBaseSubscriptionCallback::OnReportEnd() { - if (mInterimReportBlock) { - dispatch_block_cancel(mInterimReportBlock); - mInterimReportBlock = nil; - } ReportData(); if (mReportEndHandler) { mReportEndHandler();