<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Matter subscription fails after some time causing weird state</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/124869/matter-subscription-fails-after-some-time-causing-weird-state</link><description>Hi, 
 I&amp;#39;m developing a Matter device based on the Window Covering sample. I have added another endpoint to the device containing some sensor clusters and it all works after commissioning. But after some time (sometimes minutes sometimes up to 20 hours</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Sun, 23 Nov 2025 11:03:41 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/124869/matter-subscription-fails-after-some-time-causing-weird-state" /><item><title>RE: Matter subscription fails after some time causing weird state</title><link>https://devzone.nordicsemi.com/thread/555118?ContentTypeID=1</link><pubDate>Sun, 23 Nov 2025 11:03:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:486c1c77-ec8c-45a2-84a4-63f90f519ac0</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;Sorry for the delayed reply. Maria is OoO and I will try to help you with this if you still have this issue.&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I am not an expert but seems like calling Matter setters from your sensor thread without going through the CHIP thread causes instability. I tis better to schedule a CHIP thread and&amp;nbsp;Call&amp;nbsp;&lt;span&gt;UpdateCo2(matter_co2);&lt;/span&gt;&amp;nbsp;from your sensor thread. This runs on the CHIP thread, no lock contention&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;void UpdateCo2(float co2)
{
    PlatformMgr().ScheduleWork([](intptr_t arg) {
        const float value = static_cast&amp;lt;float&amp;gt;(arg);
        gCarbonDioxideConcentrationMeasurementInstance.SetMeasuredValue(
            chip::app::DataModel::MakeNullable(value));
    }, static_cast&amp;lt;intptr_t&amp;gt;(co2));
}
&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;The other option is to use the stack lock but it might have corner cases if you have long critical sections.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Matter subscription fails after some time causing weird state</title><link>https://devzone.nordicsemi.com/thread/552045?ContentTypeID=1</link><pubDate>Tue, 21 Oct 2025 10:01:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fd82221f-30f7-442e-92be-adfd53c8cfa6</guid><dc:creator>Tiit</dc:creator><description>&lt;p&gt;Hi Maria,&lt;/p&gt;
&lt;p&gt;So far the locking seems to have fixed the stability issue.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;But subscriptions still seem to be limited to one. See this log from the device:&lt;/p&gt;
&lt;p&gt;[00:14:38.393,127] &amp;lt;dbg&amp;gt; chip: LogV: [IM]Received Subscribe request&lt;br /&gt;[00:14:38.395,172] &amp;lt;inf&amp;gt; chip: [IM]Deleting previous subscription from NodeId: 000000000001B669, FabricIndex: 1&lt;br /&gt;[00:14:38.397,888] &amp;lt;inf&amp;gt; chip: [DMG]Subscription id 0xf54ff378 from node &amp;lt;000000000001B669, 1&amp;gt; torn down&lt;br /&gt;[00:14:38.401,397] &amp;lt;inf&amp;gt; chip: [DMG]Final negotiated min/max parameters: Min = 10s, Max = 120s&lt;/p&gt;
&lt;p&gt;The weird thing is the device does seem to work correctly if I add it to Home Assistant for example. I can see all sensor values updating and logging correctly. But if I try to use chip-tool to manually subscribe to attributes then there seems to be a limit. And as far as I can tell the limit seems to be on the device side as chip-tool will report a timeout for the old subscription. This timeout leads me to believe that it was not expecting the old subscription to go away.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Should I create a new ticket for the subscription limit issue or is it ok to continue this here? This issue is not blocking me from moving forward with my development but I do find this odd and would like to find the reason for it happening here.&lt;/p&gt;
&lt;p&gt;Tiit&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Matter subscription fails after some time causing weird state</title><link>https://devzone.nordicsemi.com/thread/551945?ContentTypeID=1</link><pubDate>Mon, 20 Oct 2025 12:51:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8bc375d1-dfe7-4671-b1a8-c6cca9a8e660</guid><dc:creator>Maria Gilje</dc:creator><description>&lt;p&gt;Hi Tiit,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Great find about the Lock/UnlockChipStack functions. I can see now that it is recommended to use them when calling functions which update attributes when you are not already in a Matter context. See &lt;a href="https://github.com/project-chip/connectedhomeip/issues/29181#issuecomment-1717765419"&gt;this reply&lt;/a&gt; to related GitHub issue for some general guidelines for when to use the Lock/UnlockChipStack functions. Note that calling LockChipStack when the stack is already locked can cause a deadlock.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Did you see improvement after letting your updated application run for a while?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Maria&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Matter subscription fails after some time causing weird state</title><link>https://devzone.nordicsemi.com/thread/551608?ContentTypeID=1</link><pubDate>Wed, 15 Oct 2025 14:25:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5fd6cac3-77c4-4253-979b-8d504c46d219</guid><dc:creator>Tiit</dc:creator><description>&lt;p&gt;Hi Maria,&lt;/p&gt;
&lt;p&gt;I was optimizing the memory use when I found something that leads me to believe the issue may be data synchronization between threads instead. I followed the memory optimization guide you linked but honestly saving large amounts seems pretty much impossible. Most of the bigger chunks are used up by things that come with Thread, Matter and BLE. Those I have very little control over unless I really want to dive deep into how they work. So for now I just optimized the stacks and cleaned up some unused stuff but it had no effect on the stability. So on suggestion from a colleague I tried just removing some of our own threads temporarily to save bigger chunks of memory. One of these threads was the one pushing new sensor values to Matter. This made it so that the code now doesn&amp;#39;t crash at all. So today I tried putting back everything else but just commented out the part where we update matter attribute values. And this is also stable.&lt;/p&gt;
&lt;p&gt;What I&amp;#39;m going to try next is just updating Matter attributes one by one starting with co2. If I just run this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;gCarbonDioxideConcentrationMeasurementInstance.SetMeasuredValue(chip::app::DataModel::MakeNullable(float(matter_co2)));&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The code will eventually crash. This is called from our sensor thread and I think this is actually meant to be called in some other way or from some other context.&lt;/p&gt;
&lt;p&gt;What I&amp;#39;m trying next (and it hasn&amp;#39;t crashed so far) is this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;	matter_co2++;
	PlatformMgr().LockChipStack();
    gCarbonDioxideConcentrationMeasurementInstance.SetMeasuredValue(chip::app::DataModel::MakeNullable(float(matter_co2)));
	PlatformMgr().UnlockChipStack();&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I&amp;#39;m hoping to see this still running as I come to work tomorrow. If that works I will try to add all the other attribute updates back with the same protection around the matter code. All the examples seem to have a very complex way of structuring the code that I&amp;#39;m having a hard time following. They mostly seem to work with work queues somehow but I have not found a good way to integrate all that with my own code. Ideally I want to just have two functions that my application calls: init and update. I just want to periodically call update to push new sensor values to matter and that&amp;#39;s it.&lt;/p&gt;
&lt;p&gt;Tiit&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Matter subscription fails after some time causing weird state</title><link>https://devzone.nordicsemi.com/thread/551606?ContentTypeID=1</link><pubDate>Wed, 15 Oct 2025 14:05:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a2e3a8fb-f169-4639-ad01-cd676abee7fc</guid><dc:creator>Maria Gilje</dc:creator><description>&lt;p&gt;Hi Tiit,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Thank you for your patience.&amp;nbsp;&lt;/p&gt;
[quote user="Tiit Ratsep"]Yes, I&amp;#39;m setting up subscriptions in interactive mode. And they do seem to work for a while. And then they randomly stop and I can&amp;#39;t subscribe again until I restart the board.[/quote]
&lt;p&gt;Thank you for confirming. We will need to do some more investigations on what could be the cause for the subscription stopping after a while.&amp;nbsp;&lt;/p&gt;
[quote user="Tiit Ratsep"]&lt;p&gt;First the memory report that comes after compiling (that looks ok to me):&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Memory region Used Size Region Size %age Used&lt;br /&gt; FLASH: 841456 B 982528 B 85.64%&lt;br /&gt; RAM: 214861 B 256 KB 81.96%&lt;br /&gt; IDT_LIST: 0 GB 32 KB 0.00%&lt;/p&gt;[/quote]
&lt;p&gt;I agree, they seem to be at an OK usage percentage.&amp;nbsp;&lt;/p&gt;
[quote user="Tiit Ratsep"]And now the RAM report from the memory report tool that is a bit difficult to share here. But it does say that the total used memory is 288.25 KB which does not seem good. But I don&amp;#39;t know how to optimize that.[/quote]
&lt;p&gt;We have a general guide for &lt;a href="https://docs.nordicsemi.com/bundle/ncs-latest/page/nrf/test_and_optimize/optimizing/memory.html"&gt;memory footprint optimization&lt;/a&gt;&amp;nbsp;which could be of help here.&amp;nbsp;&amp;nbsp;&lt;/p&gt;
[quote user="Tiit Ratsep"]The largest buffers seem to be mostly Matter and Thread which are created by the SDK I guess. I can probably reduce Heap as I don&amp;#39;t really use that at all. Maybe I can optimize the stack size of the threads we use (and main) but those are tiny compared to the huge buffers. Do you think this may be the issue? How does it even work at all if the memory use is so much higher than the actual RAM in the SOC. I&amp;#39;m not really sure how variables inside function scope work in Zephyr - are they always allocated or are the temporary variables stored in the stack? I can&amp;#39;t really see how big the stack grows here but if the memory is already low maybe stack hits something important in RAM and that&amp;#39;s when it breaks? Can you suggest something to debug this situation?[/quote]
&lt;p&gt;I need more time to look into this, but in the mean time some general debugging tips are found in &lt;a href="https://academy.nordicsemi.com/courses/nrf-connect-sdk-intermediate/lessons/lesson-2-debugging/"&gt;Lesson 2&lt;/a&gt; from the nRF Connect SDK Intermediate course.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Maria&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Matter subscription fails after some time causing weird state</title><link>https://devzone.nordicsemi.com/thread/551222?ContentTypeID=1</link><pubDate>Mon, 13 Oct 2025 07:47:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c99b82f7-36f2-4322-949c-5500e89de8d3</guid><dc:creator>Tiit</dc:creator><description>&lt;p&gt;Hi Maria,&lt;/p&gt;
&lt;p&gt;Yes, I&amp;#39;m setting up subscriptions in interactive mode. And they do seem to work for a while. And then they randomly stop and I can&amp;#39;t subscribe again until I restart the board.&lt;/p&gt;
&lt;p&gt;I have actually never tried the memory report thing before. I took a long time to generate but honestly I don&amp;#39;t know how to read that. I will try to share it here so you can look at it and say if this looks ok.&lt;/p&gt;
&lt;p&gt;First the memory report that comes after compiling (that looks ok to me):&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Memory region Used Size Region Size %age Used&lt;br /&gt; FLASH: 841456 B 982528 B 85.64%&lt;br /&gt; RAM: 214861 B 256 KB 81.96%&lt;br /&gt; IDT_LIST: 0 GB 32 KB 0.00%&lt;/p&gt;
&lt;p&gt;And now the RAM report from the memory report tool that is a bit difficult to share here. But it does say that the total used memory is 288.25 KB which does not seem good. But I don&amp;#39;t know how to optimize that.&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/Screenshot-from-2025_2D00_10_2D00_13-10_2D00_38_2D00_24.png" /&gt;&lt;/p&gt;
&lt;p&gt;The largest buffers seem to be mostly Matter and Thread which are created by the SDK I guess. I can probably reduce Heap as I don&amp;#39;t really use that at all. Maybe I can optimize the stack size of the threads we use (and main) but those are tiny compared to the huge buffers. Do you think this may be the issue? How does it even work at all if the memory use is so much higher than the actual RAM in the SOC. I&amp;#39;m not really sure how variables inside function scope work in Zephyr - are they always allocated or are the temporary variables stored in the stack? I can&amp;#39;t really see how big the stack grows here but if the memory is already low maybe stack hits something important in RAM and that&amp;#39;s when it breaks? Can you suggest something to debug this situation?&lt;/p&gt;
&lt;p&gt;Tiit&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Matter subscription fails after some time causing weird state</title><link>https://devzone.nordicsemi.com/thread/551135?ContentTypeID=1</link><pubDate>Fri, 10 Oct 2025 12:59:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:aa8cf61f-82eb-4204-99c3-124a452ad54b</guid><dc:creator>Maria Gilje</dc:creator><description>&lt;p&gt;Hi Tiit,&amp;nbsp;&lt;/p&gt;
[quote user=""]1. Why does the device always delete the previous subscription when I add a new one? Is this expected behaviour?[/quote]
&lt;p&gt;This seems odd. It should be possible for the chip-tool or other Matter controllers to have several subscriptions running, as long as the subscriber-publisher pair is unique. I&amp;#39;ll report this internally to check if anyone else has seen similar issues.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Edit: Just to be sure, you are setting up the subscriptions in &lt;a href="https://docs.nordicsemi.com/bundle/ncs-latest/page/matter/chip_tool_guide.html#interactive_mode"&gt;interactive mode&lt;/a&gt;, right?&amp;nbsp;&lt;/p&gt;
[quote user=""]2. Why does the device become unresponsive like this?[/quote]
&lt;p&gt;Like you hypothesize this could be because of memory. What does the memory reports in your build log show? High percentages in that table are good indicators that the device is running out of memory. If this is the case, then make sure that you are using good practices to free up memory where possible.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Maria&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>