<?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>poll() not blocking</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/76268/poll-not-blocking</link><description>Hello, 
 I am using the Nordic SDK v1.5.0, the modem firmware is mfw_nrf9160_1.2.3 and the DK for the nRF9160 
 In our application, we are using AT commands to setup and control the modem. On startup, the modem PSM and eDRX 
 features are switched off</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 15 Jun 2021 05:52:27 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/76268/poll-not-blocking" /><item><title>RE: poll() not blocking</title><link>https://devzone.nordicsemi.com/thread/315272?ContentTypeID=1</link><pubDate>Tue, 15 Jun 2021 05:52:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:35dfac27-33d8-4487-b0ab-1f6334612740</guid><dc:creator>NelsonGoncalves</dc:creator><description>&lt;p&gt;Hey,&lt;/p&gt;
&lt;p&gt;I was able to sidestep this bug by only passing the currently open sockets to poll(), so this is no longer an issue for us.&lt;/p&gt;
&lt;p&gt;Right now it is not opportune for me upgrade the modem firmware, I will postpone that to the end of our sprint.&lt;/p&gt;
&lt;p&gt;Thanks for help,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;Nelson&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: poll() not blocking</title><link>https://devzone.nordicsemi.com/thread/315198?ContentTypeID=1</link><pubDate>Mon, 14 Jun 2021 15:07:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a7a4757d-1989-4768-97f8-2f8a19141f2d</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;span style="text-decoration:line-through;"&gt;I tried reproducing this by modifying mqtt_simple to use an fd array instead, and setting fds[1].fd = -1, but I wasn&amp;#39;t able, unfortunately. Could you provide the contents of &amp;quot;pollSet&amp;quot;&amp;nbsp;variable when you were able to reproduce this?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;My deepest apologies. This is indeed a bug. I was not on the same libmodem version as you were.&lt;/p&gt;
&lt;p&gt;This seems to be fixed in libmodem v1.1.0:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/nrfconnect/sdk-nrfxlib/blob/master/nrf_modem/doc/CHANGELOG.rst#nrf_modem-110"&gt;https://github.com/nrfconnect/sdk-nrfxlib/blob/master/nrf_modem/doc/CHANGELOG.rst#nrf_modem-110&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Could you also verify that this fixes the issue on your side?&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: poll() not blocking</title><link>https://devzone.nordicsemi.com/thread/315104?ContentTypeID=1</link><pubDate>Mon, 14 Jun 2021 11:46:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:26023702-32a5-427f-a497-d6f205829f28</guid><dc:creator>NelsonGoncalves</dc:creator><description>&lt;p&gt;Hi Hakon,&lt;/p&gt;
&lt;p&gt;The issue was indeed at the nrf_poll() call.&lt;/p&gt;
&lt;p&gt;In the original poll() call, the array of file descriptors has two sockets: client and server. However initially, only the server socket is open and the client socket number is -1.&lt;/p&gt;
&lt;p&gt;So eventually, &lt;strong&gt;nrf_poll()&lt;/strong&gt; gets called with two file descriptors (one valid, another invalid). I was expecting the negative file descriptor to be ignored&amp;nbsp;(which I understand is the standard POSIX behavior&amp;nbsp;&amp;nbsp;&lt;a href="https://man7.org/linux/man-pages/man2/poll.2.html"&gt;https://man7.org/linux/man-pages/man2/poll.2.html&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;However it does not, and instead it sets POLLNVAL on the &lt;em&gt;&lt;strong&gt;revents&amp;nbsp;&lt;/strong&gt;&lt;/em&gt;for the client socket. So technically, there is an event (invalid file descriptor), although the documentation for poll() says that negative file descriptors are ignored.&lt;/p&gt;
&lt;p&gt;Then the function&amp;nbsp;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;em&gt;&lt;strong&gt;nrf91_socket_offload_poll()&amp;nbsp;&lt;/strong&gt;&lt;/em&gt;goes through the temp array returned by &lt;strong&gt;nrf_poll&lt;/strong&gt;, to copy the events to the original function array argument&lt;span style="background-color:#ffff00;"&gt;. However it ignores negative file descriptors, but does not decrement the number of sockets with events. So the result is a return value of 1 (one socket has events), but all&amp;nbsp;&lt;strong&gt;revents&amp;nbsp;&lt;/strong&gt;fields are zero.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Long story short, if I call&amp;nbsp;&lt;strong&gt;poll()&lt;/strong&gt; with only the currently opened sockets, everything works are expected. I believe this is a deviation from the expected POSIX behavior.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;Nelson Gon&amp;ccedil;alves&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: poll() not blocking</title><link>https://devzone.nordicsemi.com/thread/315069?ContentTypeID=1</link><pubDate>Mon, 14 Jun 2021 09:51:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a8b64441-158f-4784-913a-3dfae5044191</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;
[quote user="NelsonGoncalves"]My guess is that the modem firmware is not properly initialized, although I don&amp;#39;t know why or where.&amp;nbsp; The modem is registered on the network, there is an active PDP context and the modem has an IP address.[/quote]
&lt;p&gt;If you are connected to the network, I do not see how anything can not be initialized.&amp;nbsp;&lt;/p&gt;
[quote user="NelsonGoncalves"]This function looks correct, but the actual implementation is done in&amp;nbsp;&lt;em&gt;&lt;strong&gt;nrf_poll()&amp;nbsp;&lt;/strong&gt;&lt;/em&gt;&lt;strong&gt;&lt;/strong&gt;for which I do not have the source code. This call returns 1, although all&amp;nbsp;&lt;em&gt;&lt;strong&gt;revents&lt;/strong&gt;&lt;/em&gt; fields are all zero.[/quote]
&lt;p&gt;You have verified that the return path is from nrf91_sockets.c::&lt;span&gt;nrf91_socket_offload_poll-&amp;gt;&lt;/span&gt;nrf_poll()? the offloaded function also holds a translated tmp array, could you also peek into this when it misbehaves?&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/nrfconnect/sdk-nrf/blob/master/lib/nrf_modem_lib/nrf91_sockets.c#L1008"&gt;https://github.com/nrfconnect/sdk-nrf/blob/master/lib/nrf_modem_lib/nrf91_sockets.c#L1008&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: poll() not blocking</title><link>https://devzone.nordicsemi.com/thread/315043?ContentTypeID=1</link><pubDate>Mon, 14 Jun 2021 08:10:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1118dc20-189e-4b72-b214-7dffb029b8a0</guid><dc:creator>NelsonGoncalves</dc:creator><description>&lt;p&gt;Hello Hakon,&lt;/p&gt;
&lt;p&gt;The poll() call returns 1, meaning one of the sockets has events. But after the call, for both sockets the fields&amp;nbsp;&lt;strong&gt;&lt;em&gt;revents&lt;/em&gt;&amp;nbsp;&lt;/strong&gt;is zero.&lt;/p&gt;
&lt;p&gt;SOCKET_ID_MAX is 2. I did not post the full code, but I believe the arguments to the call are correct.&lt;/p&gt;
&lt;p&gt;With the debugger, I followed the poll() call all the way down to&amp;nbsp;&lt;em&gt;&lt;strong&gt;nrf91_socket_offload_poll()&lt;/strong&gt;&lt;/em&gt;&amp;nbsp;in file &lt;em&gt;&lt;strong&gt;nrf\lib\nrf_modem_lib\nrf91_sockets.c&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;This function looks correct, but the actual implementation is done in&amp;nbsp;&lt;em&gt;&lt;strong&gt;nrf_poll()&amp;nbsp;&lt;/strong&gt;&lt;/em&gt;&lt;strong&gt;&lt;/strong&gt;for which I do not have the source code. This call returns 1, although all&amp;nbsp;&lt;em&gt;&lt;strong&gt;revents&lt;/strong&gt;&lt;/em&gt; fields are all zero.&lt;/p&gt;
&lt;p&gt;My guess is that the modem firmware is not properly initialized, although I don&amp;#39;t know why or where.&amp;nbsp; The modem is registered on the network, there is an active PDP context and the modem has an IP address.&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;&amp;nbsp; Nelson&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: poll() not blocking</title><link>https://devzone.nordicsemi.com/thread/314872?ContentTypeID=1</link><pubDate>Fri, 11 Jun 2021 10:09:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:02fc984b-ca2a-44f7-bc41-be71e8f2e7f7</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;I would recommend that you store the return from poll() and&amp;nbsp;print errno if ret &amp;lt; 0.&lt;/p&gt;
&lt;p&gt;Could you check this and come back with the errno?&lt;/p&gt;
&lt;p&gt;SOCKET_ID_MAX, what is this defined to? If this is larger than 2, you will pass uninitialized memory to poll().&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>