<?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>Network stack not recovering form Filled Buffers.</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/115166/network-stack-not-recovering-form-filled-buffers</link><description>The network stack from Zephyr is not working correctly on my nrf5340. I want to receive data from a custom driver through the network stack to my application. For this, I request network packets to be allocated and fill them with data. 
 Using the packet</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 15 Oct 2024 16:14:09 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/115166/network-stack-not-recovering-form-filled-buffers" /><item><title>RE: Network stack not recovering form Filled Buffers.</title><link>https://devzone.nordicsemi.com/thread/506355?ContentTypeID=1</link><pubDate>Tue, 15 Oct 2024 16:14:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2fa6b058-92ae-45f2-b0e9-760651603ff4</guid><dc:creator>Amanda Hsieh</dc:creator><description>&lt;p&gt;Hi,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;There’s no error handling for &lt;code&gt;zsock_recvfrom ()&lt;/code&gt; , one possibility is that the socket starts to report errors for whatever reason and is stuck in an error loop.&lt;/p&gt;
&lt;p&gt;The logic in the stack is pretty simple, if the received packet matches one of the open ports, it’s queued for the target net_context/socket, otherwise, it’s dropped. Some suggestions I could have are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;check &lt;code&gt;net conn&lt;/code&gt; command to see if there are no stray ports open accumulating packets,&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;or in the customer’s receive thread, set a socket timeout for receive (enable &lt;code&gt;CONFIG_ET_CONTEXT_RCVTIMEO&lt;/code&gt; and set &lt;code&gt;setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, ...)&lt;/code&gt; on a socket), to see, if the &lt;code&gt;zsock_recv()&lt;/code&gt; function reports no data (&lt;code&gt;-EAGAIN&lt;/code&gt; returned via errno) or whether it’s some higher-priority thread busy-looping for instance, preventing the receiver thread from running.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;But generally, I’m afraid it’d be really hard to help much here, I’ve heard of no cases of network packets being not freed which were not application errors. If we had a bug in the stack somewhere, I’m pretty sure it’d be reported on upstream Zephyr already. Debugging issues like this require a holistic approach, ideally with a debugger involved, I’m not able to give clear and certain answers based on a few code snippets only.&lt;/p&gt;
&lt;p&gt;-Amanda H.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Network stack not recovering form Filled Buffers.</title><link>https://devzone.nordicsemi.com/thread/506016?ContentTypeID=1</link><pubDate>Mon, 14 Oct 2024 07:29:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dbb5b8a0-0cfd-452f-88d5-33ebfd07f641</guid><dc:creator>StijnGerbrandaKadex</dc:creator><description>&lt;p&gt;Hi, sorry for the late response.&lt;/p&gt;
&lt;p&gt;I feel like the issue is something else. I only open one socket that I keep open. After receiving from the network stack with &lt;code&gt;zsock_recvfrom&lt;/code&gt;, I send the data into a FIFO buffer. This buffer does not seem to fill up, and the receiving thread keeps running. As far as I can see, it gets stuck on &lt;code&gt;zsock_recvfrom&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Even if the buffer were to fill, the other threads should be able to empty it over time, and some messages should be processed, right? I have tested this with multiple priority settings, and the results seem the same.&lt;/p&gt;
&lt;p&gt;I need to recover from a filled buffer and prevent it from filling up and being unable to empty.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The Receive Thread:&lt;/strong&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;	while (true /*ret &amp;gt;= 0*/) 
	{
		LOG_INF(&amp;quot;\x1B[0;35m&amp;quot; &amp;quot;receiving&amp;quot; &amp;quot;\x1b[0m&amp;quot;);
		ret = zsock_recvfrom(socketVal, (void*)(&amp;amp;(recv_data.buffer[0])), sizeof(recv_data.buffer), 0x00, (struct sockaddr *)(&amp;amp;(recv_data.sender_addr)), (socklen_t *)(&amp;amp;(recv_data.sender_addr_len)));
		if (ret &amp;gt; 0) 
		{	
			// NET_INFO(&amp;quot;UDP |Count: %d Data received: %s, Buffer Size: %u&amp;quot;, Count, recv_data.buffer, recv_data.buffer_size);
			// LOG_INF(&amp;quot;UDP &amp;quot;/*|Count: %d Data received: &amp;quot;, Count%s&amp;quot;, , recv_data.buffer*/);
			Count++;
			recv_data.buffer_size = ret;
			if (recv_data.buffer_size &amp;gt;= sizeof(recv_data.buffer))
			{
				LOG_ERR(&amp;quot;Wrong buffer size!&amp;quot;);
				k_sleep(K_SECONDS(1));
			}

			Message message;

			ret = handleEthernetInput(&amp;amp;(recv_data.buffer[0]), recv_data.buffer_size, &amp;amp;message);
			if (ret != 0)
			{
				LOG_ERR(&amp;quot;Protocol not correct&amp;quot;);
				return;
			}
		}
	}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Network stack not recovering form Filled Buffers.</title><link>https://devzone.nordicsemi.com/thread/504742?ContentTypeID=1</link><pubDate>Wed, 02 Oct 2024 17:23:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d3d735a0-e963-44d5-8275-1f0bb8c9e218</guid><dc:creator>Amanda Hsieh</dc:creator><description>&lt;p&gt;Hi,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;There’s nothing special about the driver code you shared, it looks ok. The only explanation I can think of is that you are confused about:&lt;/p&gt;
&lt;blockquote&gt;[quote user=""]And the network stack function zsock_recvfrom does not output any messages.[/quote]&lt;/blockquote&gt;
&lt;p&gt;This looks like a prefect example of data being stacked up at the application layer, with the application not consuming it. But it’s hard to say for sure, w/o seeing the full picture (full app in this case). Perhaps you have some dangling socket left open which accumulates data over time.&lt;/p&gt;
&lt;p&gt;Regards,&lt;br /&gt;Amanda H.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>