<?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>Socket send function hangs</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/102040/socket-send-function-hangs</link><description>Hi, 
 I have a custom board with nrf9160 and I&amp;#39;m using it to send messages to the AWS server via mqtt. I managed to reproduce a bug where the TLS socket send function hangs (similar to - https://devzone.nordicsemi.com/f/nordic-q-a/62249/hang-in-sendmsg</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 07 Sep 2020 14:02:40 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/102040/socket-send-function-hangs" /><item><title>RE: Socket send function hangs</title><link>https://devzone.nordicsemi.com/thread/437311?ContentTypeID=1</link><pubDate>Mon, 07 Sep 2020 14:02:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:374d1349-04fa-4257-9b0d-5b9c7001f00f</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi Nikil,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Sorry for the late response.&lt;/p&gt;
&lt;p&gt;The second trace here is also a bit strange, as there seem to be packets missing from the trace. The first one looks more complete than the second one.&lt;/p&gt;
&lt;p&gt;Based on the link that you sent, the behavior is consistent with the first trace (or the valid part of it atleast), where it takes approx. 375 seconds before the AWS server sends a TCP RST. It may indicate that network load balancer is active, as the trace shows different IPs to the same DNS when you try to initiate a connection the second time. If it is, the restriction here should apply:&amp;nbsp;&lt;a href="https://docs.aws.amazon.com/elasticloadbalancing/latest/network/network-load-balancers.html#connection-idle-timeout"&gt;https://docs.aws.amazon.com/elasticloadbalancing/latest/network/network-load-balancers.html#connection-idle-timeout&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Socket send function hangs</title><link>https://devzone.nordicsemi.com/thread/437310?ContentTypeID=1</link><pubDate>Fri, 04 Sep 2020 11:27:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2ce64a3d-93c6-4cf6-aefb-0235d3c2c042</guid><dc:creator>Nikil Rao</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;span&gt;Håkon,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Do you have any update on this? Thanks!&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Socket send function hangs</title><link>https://devzone.nordicsemi.com/thread/437309?ContentTypeID=1</link><pubDate>Tue, 01 Sep 2020 15:01:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f3c6549b-afee-42c5-83a9-663aedde579a</guid><dc:creator>Nikil Rao</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve attached a trace I took today. Yes, I&amp;#39;m using mfw 1.2.0.&lt;/p&gt;
&lt;p&gt;Another interesting thing that I found while scouring the internet to find a solution for this problem was this -&amp;nbsp;&lt;a href="https://stackoverflow.com/questions/58322484/how-to-keep-tcp-connections-alive-on-aws-network-loadbalancer"&gt;https://stackoverflow.com/questions/58322484/how-to-keep-tcp-connections-alive-on-aws-network-loadbalancer&lt;/a&gt;. I&amp;#39;m not sure if this is even related or not but maybe there&amp;#39;s some additional TCP timeout apart from the MQTT timeout which I need to set somewhere. The TCP timeout mentioned in the link above is 350 seconds which seems to be exactly the duration above which I have problems.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/trace_2D00_2020_2D00_09_2D00_01T14_2D00_40_2D00_23.284Z.bin"&gt;devzone.nordicsemi.com/.../trace_2D00_2020_2D00_09_2D00_01T14_2D00_40_2D00_23.284Z.bin&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Socket send function hangs</title><link>https://devzone.nordicsemi.com/thread/437308?ContentTypeID=1</link><pubDate>Tue, 01 Sep 2020 13:57:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:266dadf0-da3e-41b4-81af-6cc4b0e3db5a</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The trace show a TCP reset coming from the AWS server after 375 seconds, but it might be that the timestamping has been corrupted in the modem trace (its highspeed and high throughput, no UART flow control). If you provide another trace showing the issue, I can try to see if this one also shows the same behavior.&lt;/p&gt;
&lt;p&gt;You&amp;#39;re testing with mfw v1.2.0, right?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Socket send function hangs</title><link>https://devzone.nordicsemi.com/thread/437307?ContentTypeID=1</link><pubDate>Mon, 31 Aug 2020 10:56:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f2a0a2d7-26b8-4752-b548-2e6a88f32d7a</guid><dc:creator>Nikil Rao</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;span&gt;Håkon,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I have&amp;nbsp;&lt;/span&gt;&lt;em&gt;CONFIG_MQTT_KEEPALIVE=1200&amp;nbsp;&lt;/em&gt;in my code. Moreover this is what I get when I enable MQTT logs -&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;[00:00:21.134,094]&amp;lt;dbg&amp;gt; net_mqtt_sock_tls.mqtt_client_tls_connect: (0x20020ff8): Created socket 1
[00:00:31.134,979]&amp;lt;dbg&amp;gt; net_mqtt_sock_tls.mqtt_client_tls_connect: (0x20020ff8): Connect completed
[00:00:31.135,101]&amp;lt;dbg&amp;gt; net_mqtt_enc.connect_request_encode: (0x20020ff8): Encoding Protocol Description. Str:MQTT Size:00000004.
[00:00:31.135,101]&amp;lt;dbg&amp;gt; net_mqtt_enc.pack_utf8_str: (0x20020ff8): &amp;gt;&amp;gt; str_size:00000006 cur:0x2002919a, end:0x2002957d
[00:00:31.135,131]&amp;lt;dbg&amp;gt; net_mqtt_enc.pack_uint16: (0x20020ff8): &amp;gt;&amp;gt; val:0004 cur:0x2002919a, end:0x2002957d
[00:00:31.135,131]&amp;lt;dbg&amp;gt; net_mqtt_enc.connect_request_encode: (0x20020ff8): Encoding Protocol Version 04.
[00:00:31.135,131]&amp;lt;dbg&amp;gt; net_mqtt_enc.pack_uint8: (0x20020ff8): &amp;gt;&amp;gt; val:04 cur:0x200291a0, end:0x2002957d
[00:00:31.135,162]&amp;lt;dbg&amp;gt; net_mqtt_enc.pack_uint8: (0x20020ff8): &amp;gt;&amp;gt; val:00 cur:0x200291a1, end:0x2002957d
[00:00:31.135,162]&amp;lt;dbg&amp;gt; net_mqtt_enc.connect_request_encode: (0x20020ff8): Encoding Keep Alive Time 04b0.
[00:00:31.135,162]&amp;lt;dbg&amp;gt; net_mqtt_enc.pack_uint16: (0x20020ff8): &amp;gt;&amp;gt; val:04b0 cur:0x200291a2, end:0x2002957d
[00:00:31.135,162]&amp;lt;dbg&amp;gt; net_mqtt_enc.connect_request_encode: (0x20020ff8): Encoding Client Id. Str:nrf-352656100388050 Size:00000013.
[00:00:31.135,192]&amp;lt;dbg&amp;gt; net_mqtt_enc.pack_utf8_str: (0x20020ff8): &amp;gt;&amp;gt; str_size:00000015 cur:0x200291a4, end:0x2002957d
[00:00:31.135,192]&amp;lt;dbg&amp;gt; net_mqtt_enc.pack_uint16: (0x20020ff8): &amp;gt;&amp;gt; val:0013 cur:0x200291a4, end:0x2002957d
[00:00:31.135,223]&amp;lt;dbg&amp;gt; net_mqtt_enc.mqtt_encode_fixed_header: (0x20020ff8): &amp;lt;&amp;lt; msg type:0x10 length:0x0000001f
[00:00:31.135,223]&amp;lt;dbg&amp;gt; net_mqtt_enc.packet_length_encode: (0x20020ff8): &amp;gt;&amp;gt; length:0x0000001f cur:0x00000000, end:0x00000000
[00:00:31.135,223]&amp;lt;dbg&amp;gt; net_mqtt_enc.mqtt_encode_fixed_header: (0x20020ff8): Fixed header length = 02
[00:00:31.135,223]&amp;lt;dbg&amp;gt; net_mqtt_enc.pack_uint8: (0x20020ff8): &amp;gt;&amp;gt; val:10 cur:0x20029198, end:0x2002957d
[00:00:31.135,253]&amp;lt;dbg&amp;gt; net_mqtt_enc.packet_length_encode: (0x20020ff8): &amp;gt;&amp;gt; length:0x0000001f cur:0x20029199, end:0x2002957d
[00:00:31.135,986]&amp;lt;dbg&amp;gt; net_mqtt.client_connect: (0x20020ff8): Connect completed
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Encoding Keep Alive Time 04b0.&lt;/em&gt; shows that it is indeed 1200 seconds&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Socket send function hangs</title><link>https://devzone.nordicsemi.com/thread/437306?ContentTypeID=1</link><pubDate>Mon, 31 Aug 2020 10:39:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4c5d5038-abff-49da-ad50-6d2e14be6bab</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi Nikil,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Judging by the trace, it seems that the server (aws) sends a TCP RST (reset) after approx. 375 seconds, which indicates a keep-alive of 250 (1.5 * 250 = 375).&lt;/p&gt;
&lt;p&gt;Is your local MQTT keep-alive set to 250 in the trace? If yes, can you please set it to 1200 and do a new trace?&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Socket send function hangs</title><link>https://devzone.nordicsemi.com/thread/437305?ContentTypeID=1</link><pubDate>Mon, 31 Aug 2020 09:00:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:76a7e051-d667-417b-ac10-36a2732bad90</guid><dc:creator>Nikil Rao</dc:creator><description>&lt;p&gt;Hi,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Thanks a lot for the reply. I reproduced the AWS disconnect on the nrf9160dk and I&amp;#39;ve attached a modem trace. Could you please analyze it and let me know if it is indeed an NAT timeout?&lt;br /&gt;&lt;br /&gt;Yes, right now we have kept the message send interval to 300 seconds&amp;nbsp;while we wait for the new modem firmware&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/trace_2D00_2020_2D00_08_2D00_31T08_2D00_41_2D00_21.471Z.bin"&gt;devzone.nordicsemi.com/.../trace_2D00_2020_2D00_08_2D00_31T08_2D00_41_2D00_21.471Z.bin&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Socket send function hangs</title><link>https://devzone.nordicsemi.com/thread/437304?ContentTypeID=1</link><pubDate>Fri, 28 Aug 2020 13:27:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:981085f8-146d-41f5-9064-2d5e9d42f1c4</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
[quote user="Nikil Rao"]Thanks a lot for the response. Do you have an estimate on when the new modem firmware will be out?[/quote]
&lt;p&gt;&amp;nbsp;Unfortunately, I do not have the exact timeline. If you contact Thomas Page (thomas.page@nordicsemi.no) - he might have more details on this matter.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
[quote user="Nikil Rao"]Doing this however, the device needs a reset after every 20 connect cycles (every 200 minutes). Due to the high current consumption when the device resets and connects to the LTE network every 200 minutes, the lifetime of our device reduces drastically. Could you please advice on possible solutions we can try until the new modem firmware is out? Thanks![/quote]
&lt;p&gt;My apologies for the inconvenience this bug is causing. I understand that a reset is costly.&lt;/p&gt;
&lt;p&gt;I unfortunately do not have a good workaround for your case. The problem is that in the network chain, you&amp;#39;re NAT&amp;#39;ed through a LTE network, which might have their own timeouts (a &amp;quot;NAT timeout&amp;quot;) on TCP connections, which would then override any keepalive the server has on a strict IP level. If you provide a modem trace, we can verify if its the network restricting the keep-alive.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Is it a possibility to use PSM in your application, and keep the &amp;quot;keep alive&amp;quot; to under 327 sec? Or does this add up to a higher current consumption over-time compared to your current applications connect/disconnect algorithm?&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Socket send function hangs</title><link>https://devzone.nordicsemi.com/thread/437303?ContentTypeID=1</link><pubDate>Wed, 26 Aug 2020 08:39:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:149403e4-32f4-45bc-a10f-d0ddbd53c5bd</guid><dc:creator>Nikil Rao</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;span&gt;Håkon,&amp;nbsp;&lt;br /&gt;&lt;br /&gt;Thanks a lot for the response. Do you have an estimate on when the new modem firmware will be out?&lt;br /&gt;&lt;br /&gt;We have a use case where we connect to AWS and send data every 10 minutes. Since I&amp;#39;m not able to keep a connection to AWS alive for more than 5 minutes (&lt;a href="https://devzone.nordicsemi.com/support/252089"&gt;https://devzone.nordicsemi.com/support/252089&lt;/a&gt;) I&amp;#39;m trying a workaround where I send a message and then disconnect from AWS MQTT. I then reconnect after 10 minutes and do the whole cycle again. Doing this however, the device needs a reset after every 20 connect cycles (every 200 minutes). Due to the high current consumption when the device resets and connects to the LTE network every 200 minutes, the lifetime of our device reduces drastically. Could you please advice on possible solutions we can try until the new modem firmware is out? Thanks!&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Nikil&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Socket send function hangs</title><link>https://devzone.nordicsemi.com/thread/437302?ContentTypeID=1</link><pubDate>Thu, 13 Aug 2020 12:50:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:65893810-56ac-4226-a98b-056a62c4aabf</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;We recently found an issue that corresponds to your description when connect/disconnect looping with a TLS connection:&lt;/p&gt;
[quote user=""]On the 21st connection/disconnection cycle the function gets stuck[/quote]
&lt;p&gt;We are&amp;nbsp;currently testing and implementing this fix into a newer modem fw version (v1.2.2). At this time, with the currently available modem fw v1.2.0 or older), we unfortunately do not have a good workaround (a reset shall help, but that is not a good fix).&lt;/p&gt;
&lt;p&gt;I must apologize for the inconvenience this has caused.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>